I have an ItemsControl
, I've built the items that I'm displaying in it (views:DisplayGroupView
) in such a way that they will expand horizontally to show all their contents and not vertically (only using the available height)
I've changed my ItemsPanel
of the ItemsControl
to use a StackPanel
with Orientation="Horizontal"
Layout wise it's perfect, but no matter what I do I can't get it to scroll horizontally so I can see everything.
This is the XAML for the ItemsControl
:
<ItemsControl ItemsSource="{Binding DisplayGroups}" Grid.Row="1" Margin="120,20,120,20" VerticalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate >
<StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:DisplayGroupView Margin="0,0,20,0" DataContext="{Binding}" VerticalAlignment="Stretch"></views:DisplayGroupView>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This lays everything out okay, but won't scroll. I've also tried changing the ItemsControls template to include a scrollviewer, but this only stacks things vertically:
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollMode="Disabled">
<ItemsPresenter VerticalAlignment="Stretch"/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
How can I get the horizontal layout while still being able to scroll?
If you pull it out of the ItemsControl
and embed it by itself, for some reason that often acts as a workaround so something like;
<ScrollViewer VerticalScrollBarVisibilty="Disabled" HorizontalScrollBarVisibility="Auto">
<ItemsControl/>
</ScrollViewer>
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