WrapPanel not wrapping when in a StackPanel with Horizontal orientation
You can bind the WrapPanel
's MaxWidth
to the StackPanel
's ActualWidth
.
I haven't tried this, but basically:
<WrapPanel MaxWidth="{Binding ActualWidth, ElementName=myStackPanel}"/>
What you're doing isn't possible because of the algorithm that StackPanel
uses when doing horizontal layout. It's basically going to ask each child element how big it wants to be and however much space it asks for it's going to give it.
You would either need to:
- Set a
Width
orMaxWidth
on theWrapPanel
. - Use a
WrapPanel
as the outer panel in place of theStackPanel
.