Reputation: 9171
I have a itemscontrol with a scrollviewer inside of that I have a wrappanel
the thing will not wrap unless I set a width to it. Do I not understand how to use this control? Can I use it without a width? I want it to use stretch auto.
Upvotes: 1
Views: 1960
Reputation: 189457
The wrap panel must aquire from somewhere how wide its allowed to be. It sounds like you want it to be limited to the available space in the container. In that case the container must of a type that will limit the width. For example the following works fine:-
<UserControl x:Class="SilverlightApplication1.WrapPanelStuff"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkitControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">
<Grid x:Name="LayoutRoot" Background="White">
<ScrollViewer>
<toolkitControls:WrapPanel>
<Border BorderBrush="Black" BorderThickness="2">
<TextBlock Text="This should be quite long so that it takes up some horizontal space" />
</Border>
<Border BorderBrush="Black" BorderThickness="2">
<TextBlock Text="This should be quite long so that it takes up some horizontal space" />
</Border>
<Border BorderBrush="Black" BorderThickness="2">
<TextBlock Text="This should be quite long so that it takes up some horizontal space" />
</Border>
</toolkitControls:WrapPanel>
</ScrollViewer>
</Grid>
</UserControl>
The Grid
limits the WrapPanel
to the available width. Replace Grid
with Canvas
and it no longer works because Canvas
does not limit the width of its content.
Upvotes: 3
Reputation: 3617
The WrapPanel logic is going to continue placing children along the same row until it is constrained in some way. Probably the easiest way to do that without specifying a width would be to disable the horizontal scroll bar of the ScrollViewer.
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<toolkitControls:WrapPanel />
</ScrollViewer>
You could then stretch the containing ItemsControl horizontally and it should force the wrap.
Upvotes: 1