WPF 装饰器剪辑

发布于 2024-08-04 04:37:16 字数 688 浏览 6 评论 0原文

我在 ScrollViewer 中有一个 ItemsControlItemsControl 中的项目扩展为 DataTemplate,它基本上由 Adorner 组成。

现在的问题是,滚动时,Adorner 的 Visual Children 在 ScrollViewer 外部可见。假设我从水平偏移 0 滚动到 100,Adorner 的 Visual Children 移动到左侧,并且在 ScrollViewer 旁边可见,尽管它们应该是隐藏的。在 ItemsControlScrollViewer 上设置 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 Adorners, so that they are only visible in the visible scroll area?

Thanks,
Andrej

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

墨落成白 2024-08-11 04:37:16

在包含控件上设置 ClipToBounds 是不够的。您还必须设置装饰器的 IsClipEnabled 属性。

Setting ClipToBounds on the containing control is not enough. You must set the adorner's IsClipEnabled property too.

耳钉梦 2024-08-11 04:37:16

当子类化 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.

街角迷惘 2024-08-11 04:37:16

我的解决方案是将剪辑区域推送到绘图上下文上,渲染我需要的任何内容,然后在最后弹出剪辑,如下所示:

drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height)));
// continue drawing
drawingContext.Pop();

您可以将其插入到任何装饰器中,边界已经可以作为元素的一部分使用。

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:

drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height)));
// continue drawing
drawingContext.Pop();

You can plug this in into any Adorner, the bounds are already available as part of the element.

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