diff --git a/src/Avalonia.Base/Media/GeometryGroup.cs b/src/Avalonia.Base/Media/GeometryGroup.cs index cb47e61f11..0326e606f4 100644 --- a/src/Avalonia.Base/Media/GeometryGroup.cs +++ b/src/Avalonia.Base/Media/GeometryGroup.cs @@ -14,12 +14,20 @@ namespace Avalonia.Media AvaloniaProperty.RegisterDirect ( nameof(Children), o => o.Children, - SetChildren); + (o, v)=> o.Children = v); public static readonly StyledProperty FillRuleProperty = AvaloniaProperty.Register(nameof(FillRule)); - private GeometryCollection _children = new GeometryCollection(); + private GeometryCollection _children; + + public GeometryGroup() + { + _children = new GeometryCollection + { + Parent = this + }; + } /// /// Gets or sets the collection that contains the child geometries. @@ -30,7 +38,8 @@ namespace Avalonia.Media get => _children; set { - SetAndRaise(ChildrenProperty, ref _children, value); + OnChildrenChanged(_children, value); + SetAndRaise(ChildrenProperty, ref _children, value); } } @@ -56,13 +65,11 @@ namespace Avalonia.Media return result; } - private static void SetChildren(GeometryGroup geometryGroup, GeometryCollection children) + protected void OnChildrenChanged(GeometryCollection oldChildren, GeometryCollection newChildren) { - geometryGroup.Children.Parent = null; - - children.Parent = geometryGroup; + oldChildren.Parent = null; - geometryGroup.Children = children; + newChildren.Parent = this; } protected override IGeometryImpl? CreateDefiningGeometry() diff --git a/tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs b/tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs index a6078d7a4a..91183cee4b 100644 --- a/tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs +++ b/tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs @@ -24,7 +24,7 @@ namespace Avalonia.Visuals.UnitTests.Media } [Fact] - public void Childrend_Change_Should_Raise_Changed() + public void Children_Change_Should_Raise_Changed() { var target = new GeometryGroup();