WPF:网格中的 ScrollViewer
我有一个网格:
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
第二行带有滚动查看器:
<ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
<ItemsControl ItemsSource="{Binding SelectedUserControls}"/>
</ScrollViewer>
如果需要,我希望第二行带有滚动, 但如果项目控件大于屏幕,则滚动永远不可见。
如何让滚动条在需要时出现?
I have a grid:
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
The second row is with scrollviewer:
<ScrollViewer VerticalScrollBarVisibility="Auto" MinHeight="400" Grid.Row="1">
<ItemsControl ItemsSource="{Binding SelectedUserControls}"/>
</ScrollViewer>
I want the second row to be with scroll if needed,
But the scroll is never visible, event if the items controls are bigger than the screen.
How can i get the scroll to appear when needed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
尝试删除“MinHeight=400”,我敢打赌它会起作用!
您的 ItemsControl 上的 MinHeight 为 400。因此,除非您有足够的项目占据全部 400,否则您将看不到滚动条。我猜测容纳网格的容器(或者网格上的显式高度小于 400),并且您有足够的项目对于该容器来说太大,但没有足够的项目来填充 ItemsControl 的 MinHeight。
原始答案:我刚刚运行了一个测试应用程序,其中包含 30 个项目(足以填充 MinHeight),它似乎工作正常:
容纳网格的容器是否有明确的高度?
EDIT:
Try removing 'MinHeight=400' and I bet it works!!
You have a MinHeight on your ItemsControl of 400. So until you have enough items to take up all 400, you will not see your scrollbar. I'm guessing the container holding your grid (or the explicit height on your grid is less that 400), and you have enough items to be too big for that container, but not enough items to fill the MinHeight of your ItemsControl.
Original Answer: I just ran a test app with 30 items in it (enough to fill the MinHeight) and it seems to work fine:
Does your container holding your grid have an explicit Height?
将最小高度更改为最大高度。
Change MinHeight to MaxHeight.