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!
I put a stackpanel over the button. It won't affect button background. Then in the VB code I used
Chr(12)
, to indicate a line feed:You can add more lines using
Chr(12)
.Depending on your scenario you could use a UniformGrid. A few example can also be found here.
You can define it to wrap after 5 Items like this.
Each Item will, however get the exact same width, so not sure if this will work for you.
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.I don't think you can do it without a wrap panel. Maybe you can try putting a wrapPanel inside the stack panel - set its width to to the Actual width of the stack panel. You can bind it like
Width="{Binding ActualWidth, ElementName=StackPanel1}"
But this will be just a hack - i think wrap panel is the best suited for your needs.
For me, a simple
WrapPanel
works just fine: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)