diff --git a/src/Avalonia.Controls/Primitives/AdornerLayer.cs b/src/Avalonia.Controls/Primitives/AdornerLayer.cs index a469f09867..51c22c88e7 100644 --- a/src/Avalonia.Controls/Primitives/AdornerLayer.cs +++ b/src/Avalonia.Controls/Primitives/AdornerLayer.cs @@ -53,12 +53,13 @@ namespace Avalonia.Controls.Primitives foreach (var child in Children) { - var info = (AdornedElementInfo)child.GetValue(s_adornedElementInfoProperty); + var info = child.GetValue(s_adornedElementInfoProperty); if (info != null && info.Bounds.HasValue) { child.RenderTransform = new MatrixTransform(info.Bounds.Value.Transform); child.RenderTransformOrigin = new RelativePoint(new Point(0,0), RelativeUnit.Absolute); + UpdateClip(child, info.Bounds.Value); child.Arrange(info.Bounds.Value.Bounds); } else @@ -78,6 +79,19 @@ namespace Avalonia.Controls.Primitives layer?.UpdateAdornedElement(adorner, adorned); } + private void UpdateClip(IControl control, TransformedBounds bounds) + { + var clip = control.Clip as RectangleGeometry; + + if (clip == null) + { + clip = new RectangleGeometry { Transform = new MatrixTransform() }; + control.Clip = clip; + } + + clip.Rect = bounds.Clip.TransformToAABB(-bounds.Transform); + } + private void ChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) diff --git a/src/Avalonia.Visuals/VisualTree/TransformedBounds.cs b/src/Avalonia.Visuals/VisualTree/TransformedBounds.cs index 4c548669bd..435ca85a05 100644 --- a/src/Avalonia.Visuals/VisualTree/TransformedBounds.cs +++ b/src/Avalonia.Visuals/VisualTree/TransformedBounds.cs @@ -24,17 +24,17 @@ namespace Avalonia.VisualTree } /// - /// Gets the control's bounds. + /// Gets the control's bounds in its local coordinate space. /// public Rect Bounds { get; } /// - /// Gets the control's clip rectangle. + /// Gets the control's clip rectangle in global coordinate space. /// public Rect Clip { get; } /// - /// Gets the control's transform. + /// Gets the transform from local to global coordinate space. /// public Matrix Transform { get; }