wpf ItemsControl 缺少垂直滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18397839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:29:01  来源:igfitidea点击:

ItemsControl missing vertical scrollbar

wpfxamlscrollitemscontrol

提问by touyets

I have the below ItemsControlwhich 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东西可以完美地包裹物品,但它没有垂直滚动条来查看包裹的物品。如何让滚动条显示?

    <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>

回答by dkozl

ItemsControlby default does not wrap ItemsPresenterin ScrollViewerso you have to do it manually like so:

ItemsControl默认情况下不换行ItemsPresenterScrollViewer因此您必须像这样手动完成:

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

回答by Jonathan

Wrap your ItemsControlin a ScrollViewercontrol.

将您包裹ItemsControl在一个ScrollViewer控件中。

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

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

请记住将Grid.Column="0" Grid.Row="1"属性放在 ScrollViewer 中,而不是放在 ItemControl 中。

回答by J R B

Use ScrollViewer and set the property "VerticalScrollBarVisibility" true.

使用 ScrollViewer 并将属性“VerticalScrollBarVisibility”设置为 true。

< ScrollViewer VerticalScrollBarVisibility="Auto">

< ScrollViewer VerticalScrollBarVisibility="Auto">

Here your ItemsControl

在这里你的 ItemsControl

< /ScrollViewer>

< /滚动查看器>