8

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>
Robert S.
  • 25,266
  • 14
  • 84
  • 116
Marchy
  • 3,334
  • 5
  • 37
  • 27

3 Answers3

22

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>
Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
1

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

Just add:

<TextBlock Text="&#xD;"/>
Wobbles
  • 3,033
  • 1
  • 25
  • 51
0

Could just add a Margin to the control that is to be on the new line:

<TextBlock Margin="0,20,0,0">5</TextBlock>