is it possible to wrap content in a StackPanel
?
I know that we can make use of a WrapPanel
instead.
But for code modifying reasons, I must make use of a StackPanel
.
So, is there a way to make the items in a StackPanel
wrap after say 5 items...
Thanks!
Create nested StackPanel
s which contain the required number of items.
In the example below, you have two rows, respectively occupied by the <StackPanel Orientation="Horizontal">
elements, which in turn each contain five items that will be displayed horizontally next to each other.
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Item1 />
<Item2 />
<Item3 />
<Item4 />
<Item5 />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Item1 />
<Item2 />
<Item3 />
<Item4 />
<Item5 />
</StackPanel>
</StackPanel>
For me, a simple WrapPanel
works just fine:
<WrapPanel Orientation="Horizontal" Width="500" />
Not inside a StackPanel
or any other container. And setting Width to a constant value can be superior im some cases, because binding it to ActualWidth can prevent down-sizing (e.g. when parent control is down-sized, WrapPanel is not)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With