15

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>
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
touyets
  • 1,315
  • 6
  • 19
  • 34

3 Answers3

31

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>
dkozl
  • 32,814
  • 8
  • 87
  • 89
  • Very strange... I tried it 20x before and it didn't work and now it does... Thank you! – touyets Aug 23 '13 at 08:23
  • 2
    I figured out the problem: if I enter a value for the horizontal scrollbar visibility of the scrollviewer then it doesn't work properly – touyets Aug 23 '13 at 09:15
  • 1
    If this is not working, please add height of parent element of scrollviewer. ... – DevCaf Apr 21 '21 at 00:57
8

Wrap your ItemsControl in a ScrollViewer control.

<ScrollViewer VerticalScrollBarVisibility="Auto">
  <ItemsControl ...
</ScrollViewer>

Remember to put the Grid.Column="0" Grid.Row="1" attributes in the ScrollViewer instead of in your ItemControl.

Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107
Jonathan
  • 11,809
  • 5
  • 57
  • 91
0

Use ScrollViewer and set the property "VerticalScrollBarVisibility" true.

< ScrollViewer VerticalScrollBarVisibility="Auto">

Here your ItemsControl

< /ScrollViewer>

J R B
  • 2,069
  • 4
  • 17
  • 32