Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force a WrapPanel to insert a "newline" in WPF?

Tags:

wpf

If I am inserting elements into a wrap panel and there is still space in the panel before it overflows on the next line, can I specifically make it wrap over so that the subsequent elements are on the next line?

I am looking for something like this:

<WrapPanel>
  <Element/>
  <Element/>

  <NewLine???/>

  <Element/>
  <Element/>
  <Element/>
</WrapPanel>
like image 575
Marchy Avatar asked Dec 04 '08 20:12

Marchy


People also ask

How to force a wrappanel to move to the next row?

I think I figured out what you're trying to ask. If you have a WrapPanel that is laying out by row, and you want to force it to the next row, you can replace the single WrapPanel with If you want to preserve wrapping of individual rows, you can use WrapPanel s inside the vertical StackPanel.

How do I replace a single wrappanel with a StackPanel?

If you have a WrapPanel that is laying out by row, and you want to force it to the next row, you can replace the single WrapPanel with If you want to preserve wrapping of individual rows, you can use WrapPanel s inside the vertical StackPanel.

How to add newline in PA JSON of a SharePoint field?

For multi-line fields, the easiest way is to use the Unicode for a newline and put \u000a wherever you want to add a newline in the PA JSON of a SharePoint field. 05-13-2020 08:18 AM thx this worked for me !

How to preserve wrapping of individual rows in a StackPanel?

If you want to preserve wrapping of individual rows, you can use WrapPanel s inside the vertical StackPanel. Thanks for contributing an answer to Stack Overflow!


2 Answers

This works:

<WrapPanel>
    <TextBlock>1</TextBlock>
    <TextBlock>2</TextBlock>
    <TextBlock>3</TextBlock>
    <TextBlock>4</TextBlock>

    <TextBlock Width="10000" Height="0" />

    <TextBlock>5</TextBlock>
    <TextBlock>6</TextBlock>
</WrapPanel>

I have to add though... this is pretty much a hack. You might want to consider using a StackPanel, and inside of that, have a WrapPanel with the items you want to Wrap... Example:

<StackPanel>
    <WrapPanel>
        <TextBlock>1</TextBlock>
        <TextBlock>2</TextBlock>
        <TextBlock>3</TextBlock>
        <TextBlock>4</TextBlock>
    </WrapPanel>
    <WrapPanel>
        <TextBlock>5</TextBlock>
        <TextBlock>6</TextBlock>
    </WrapPanel>
</StackPanel>
like image 130
Timothy Khouri Avatar answered Sep 30 '22 06:09

Timothy Khouri


From https://stackoverflow.com/a/3587172/3797778

Just add:

<TextBlock Text="&#xD;"/>
like image 23
Wobbles Avatar answered Sep 30 '22 06:09

Wobbles