Question

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>
Était-ce utile?

La solution

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>

Autres conseils

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.

Use ScrollViewer and set the property "VerticalScrollBarVisibility" true.

< ScrollViewer VerticalScrollBarVisibility="Auto">

Here your ItemsControl

< /ScrollViewer>

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top