WPF Adorner Clipping

后端 未结 3 1993
一整个雨季
一整个雨季 2021-02-20 15:56

I have an ItemsControl in a ScrollViewer. The items in the ItemsControl are expanded to a DataTemplate which basically consis

相关标签:
3条回答
  • 2021-02-20 16:18

    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.

    0 讨论(0)
  • 2021-02-20 16:29

    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.

    0 讨论(0)
  • 2021-02-20 16:33

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

    0 讨论(0)
提交回复
热议问题