ItemsControl missing vertical scrollbar

假如想象 提交于 2019-12-04 17:47:25

问题


I have the below ItemsControl which wraps items perfectly but it does not have a vertical scrollbar so I can not 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>

回答1:


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>



回答2:


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.




回答3:


Use ScrollViewer and set the property "VerticalScrollBarVisibility" true.

< ScrollViewer VerticalScrollBarVisibility="Auto">

Here your ItemsControl

< /ScrollViewer>



来源:https://stackoverflow.com/questions/18397839/itemscontrol-missing-vertical-scrollbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!