如何知道 ItemsControl 何时溢出其 ScrollViewer?

发布于 2024-08-07 02:44:08 字数 267 浏览 3 评论 0原文

当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱给你人给你 2024-08-14 02:44:08

好吧,我最终自己解决了这个问题。

就我而言,我使用逻辑滚动而不是物理滚动,并且由于我有水平布局,所以我所要做的就是在 ScrollViewer.ScrollableWidth 上触发。在我的例子中实现此功能的秘诀是确保将 ScrollViewer.Horizo​​ntalScrollBarVisibility 设置为“隐藏”而不是“禁用”。这将允许内容滚动,并使scrollableWidth 属性实际上具有有意义的值。

笔记:
奇怪的是,将 Horizo​​ntalScrollBarVisibility 设置为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文