如何让 ListBox 滚动条在 ScrollViewer 中出现?
我有一个 ScrollViewer,其中包含一个 DockPanel,其中包含一个 ListBox 作为其填充元素。我面临的问题是,当 ListBox
包含许多项目,并且窗口的高度减小到需要滚动条的程度时,ScrollViewer
'滚动条出现,将我的 DockPanel.Dock="Bottom"
控件推离屏幕。 ListBox
的滚动条永远不会出现。相反,当窗口高度减小时,我希望首先出现 ListBox
的滚动条。然后,在 ListBox
缩小到我指定的某个最小高度后,ScrollViewer
的滚动条应该会处理其余的事情。
怎么办?
I have a ScrollViewer
, which contains a DockPanel
, which contains a ListBox
as its filled element. The problem I'm facing is that, when the ListBox
contains many items, and the height of the window is reduced to the point where a scrollbar is necessary, the ScrollViewer
's scrollbar appears, pushing my controls with DockPanel.Dock="Bottom"
off the screen. The ListBox
's scrollbar never appears. Instead, when the window height is reduced, I would like the ListBox
's scrollbar to appear first. Then, after the ListBox
shrinks to some minimum height that I specify, the ScrollViewer
's scrollbar should appear to take care of the rest.
How do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将 ListView 的 MinHeight 属性设置为您希望 ScrollViewer 的 ScrollBar 显示或启用的特定高度。 ListView 的 Height 属性应绑定到 ScrollViewer 的 Height 属性。然后,当窗口的高度减小到隐藏 ListView 中的部分列表的高度时,ListView 的 ScrollBar 就会出现。当 ListView 的高度达到 MinHeight 时,ScrollViewer 的 ScrollBar 就会出现。
这是 Xaml 代码:
You Should set the ListView's MinHeight property to the specific height which you want the ScrollViewer's ScrollBar to apear or being enabled. The ListView's Height Property should be bind to the ScrollViewer's Height Property. Then when the Window's Height is reduced to an Height which is hide some of the list in the ListView, the ListView's ScrollBar apears. when the ListView's Height reaches its MinHeight the ScrollViewer's ScrollBar apears.
This is The Xaml code: