如何知道 ItemsControl 何时溢出其 ScrollViewer?
当 ItemsControl 中的项目溢出其容器时,如何使用触发器交换模板?
在我当前的实现中,我想根据 ItemsControl 的当前状态显示更简短的模板形式,如果滚动条可见性设置为“自动”,内容是否会导致 ScrollViwer 的滚动条出现。因此,我对 ScrollViewer 或 ItemsControl 上的任何属性都感兴趣,这可能会给我提供有关 ScrollViewer 是否溢出的线索。如果我必须使用一些自定义 ValueConverter 来创建一个合理的布尔值来绑定,我想这也可以。
How would one swap a template by using a Trigger when the items within an ItemsControl overflow its container?
In my current implementation I would like to show a more brief form of template based on whether the current state of the ItemsControl are such that the content would cause a ScrollViwer's scroll bars to appear if the scroll bar visibility was set to Auto. So I'm interested in any property either on the ScrollViewer or the ItemsControl which may give me a clue about whether it is overflowing it's ScrollViewer. If I have to use some custom ValueConverter to make a sensible boolean value to bind to I guess that would be alright too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我最终自己解决了这个问题。
就我而言,我使用逻辑滚动而不是物理滚动,并且由于我有水平布局,所以我所要做的就是在 ScrollViewer.ScrollableWidth 上触发。在我的例子中实现此功能的秘诀是确保将 ScrollViewer.HorizontalScrollBarVisibility 设置为“隐藏”而不是“禁用”。这将允许内容滚动,并使scrollableWidth 属性实际上具有有意义的值。
笔记:
奇怪的是,将 HorizontalScrollBarVisibility 设置为 Hidden 似乎会在视觉上折叠滚动条,因此我不完全确定在这种情况下 Collapse 和 Hidden 之间有什么区别。
Ok so I ended up figuring this one out myself.
In my case I'm using Logical Scrolling as opposed to physical scrolling and since I'm have a horizontal layout all I had to do was to trigger on the ScrollViewer.ScrollableWidth. The secret to getting this working in my case was to make sure that I set ScrollViewer.HorizontalScrollBarVisibility to Hidden as opposed to Disabled. This will alow the content to be scrolled and will make it so that the scrollableWidth property actually has a meaningful value.
NOTE:
Curiously setting HorizontalScrollBarVisibility to Hidden seems to collapse the scroll bar visually so I'm not entirely sure what the difference is between Collapse and Hidden in this case.