ItemsControl missing vertical scrollbar

touyets picture touyets · Aug 23, 2013 · Viewed 14.7k times · Source

I have the below ItemsControl which wraps items perfectly but it does not have a vertical scrollbar to see the wrapped items. How can I get the scrollbar to show?

    <ItemsControl x:Name="tStack" Grid.Column="0" Grid.Row="1"
                  ItemsSource="{Binding Shows.View}"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  BorderThickness="0.5">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal" HorizontalAlignment="Left"
                           VerticalAlignment="Top"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Viewbox HorizontalAlignment="Left"  Height="250">
                    <Controls1:MyShowsUserControl Padding="10"/>
                </Viewbox>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

Answer

dkozl picture dkozl · Aug 23, 2013

ItemsControl by default does not wrap ItemsPresenter in ScrollViewer so you have to do it manually like so:

<ScrollViewer Grid.Column="0" Grid.Row="1">
   <ItemsControl x:Name="tStack" ... >
      <!-- .... -->
   </ItemsControl>
</ScrollViewer>