0

Is there a way to make the WrapPanel's height calculated automatically depending on its children?

I mean I wanted it to keep extending until all items got fitted.

Note: The desire behavior is to extend vertically since its Orientation is Horizontal and its width is fixed.

Homam
  • 23,263
  • 32
  • 111
  • 187

3 Answers3

0

What about simply placing the WrapPanel in a StackPanel, which typically grows as its content grows?

<StackPanel>
    <WrapPanel Width="400" ...>
        ...
    </WrapPanel>
</StackPanel>
Rachel
  • 130,264
  • 66
  • 304
  • 490
0

If you put the WrapPanel in a grid row with height set to Auto, it will grow as more content is added. Like so:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <WrapPanel />
</Grid>
Eirik
  • 4,135
  • 27
  • 29
0

It's a bit late for this answer, but someone might find it useful. All you have to do is to set wrappanel's HorizontalAlignment and VerticalAlignment depending on the wrap panel orientation, e.g. set HorizontalAlignment="Stretch" and VerticalAlignment="Top" an then your wrappanel grows as you add children to it.

Branko
  • 27
  • 1
  • 6