WPF 装饰器剪辑
我在 ScrollViewer
中有一个 ItemsControl
。 ItemsControl
中的项目扩展为 DataTemplate
,它基本上由 Adorner
组成。
现在的问题是,滚动时,Adorner
的 Visual Children 在 ScrollViewer
外部可见。假设我从水平偏移 0 滚动到 100,Adorner
的 Visual Children 移动到左侧,并且在 ScrollViewer
旁边可见,尽管它们应该是隐藏的。在 ItemsControl
或 ScrollViewer
上设置 ClipToBounds
不起作用。
据我所知,Adorner
会按 z 顺序呈现在所有元素之上,但在使用 ScrollViewer
的情况下,它们实际上不应该可见。顺便说一下,装饰后的 Element
的行为与预期一致,并且通过 ScrollViewer
不可见。
有没有简单的方法来“剪辑”Adorner,以便它们仅在可见滚动区域中可见?
谢谢, 安德烈
I have an ItemsControl
in a ScrollViewer
. The items in the ItemsControl
are expanded to a DataTemplate
which basically consists of an Adorner
.
Now the problem is, when scrolling, the Visual Children of the Adorner
are visible outside the ScrollViewer
. Lets say I scroll from the Horizontal Offset 0 to 100, the Visual Children of the Adorner
move to the left and are visible next to the ScrollViewer
, although they should be hidden. Setting ClipToBounds
on the ItemsControl
or the ScrollViewer
does not work.
I understand, that Adorner
are rendered above all elements z-order wise, but they really shouldn't be visible in such cases as with the ScrollViewer
. The adorned Element
by the way behaves like expected and is not visible through the ScrollViewer
.
Is there any easy way to "clip" the Adorner
s, so that they are only visible in the visible scroll area?
Thanks,
Andrej
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在包含控件上设置
ClipToBounds
是不够的。您还必须设置装饰器的IsClipEnabled
属性。Setting
ClipToBounds
on the containing control is not enough. You must set the adorner'sIsClipEnabled
property too.当子类化 WPFToolkit DataGrid 以在当前单元格周围绘制装饰器时,我遇到了同样的问题。
ScrollViewer 的内容由 ScrollContentPresenter 实例呈现。 ScrollContentPresenter 有自己的装饰器层,可以通过 ScrollContentPresenter.AdornerLayer 属性访问该装饰器层。
我发现如果我将装饰器添加到该层,它会正确剪辑。
I've encountered the same problem when subclassing the WPFToolkit DataGrid to draw an adorner around the current cell.
The content of the ScrollViewer is rendered by a ScrollContentPresenter instance. ScrollContentPresenter has its own adorner layer, which is accessible through the ScrollContentPresenter.AdornerLayer property.
I found that my adorner correctly clips if I add it to that layer.
我的解决方案是将剪辑区域推送到绘图上下文上,渲染我需要的任何内容,然后在最后弹出剪辑,如下所示:
您可以将其插入到任何装饰器中,边界已经可以作为元素的一部分使用。
My solution was to push a clip region onto the drawing context, render whatever I needed, and pop the clipping at the end, like this:
You can plug this in into any Adorner, the bounds are already available as part of the element.