diff --git a/src/Avalonia.Base/Media/GeometryGroup.cs b/src/Avalonia.Base/Media/GeometryGroup.cs index b3b807c0a0..dbd1b9c97c 100644 --- a/src/Avalonia.Base/Media/GeometryGroup.cs +++ b/src/Avalonia.Base/Media/GeometryGroup.cs @@ -14,7 +14,7 @@ namespace Avalonia.Media AvaloniaProperty.RegisterDirect ( nameof(Children), o => o.Children, - (o, v) => o.Children = v); + SetChildren); public static readonly StyledProperty FillRuleProperty = AvaloniaProperty.Register(nameof(FillRule)); @@ -29,18 +29,12 @@ namespace Avalonia.Media { get => _children; set - { - if(_children is GeometryCollection) - { - _children.Parent = null; - } - - if (value is GeometryCollection) - { - value.Parent = this; - } + { + _children.Parent = null; SetAndRaise(ChildrenProperty, ref _children, value); + + _children.Parent = this; } } @@ -66,6 +60,15 @@ namespace Avalonia.Media return result; } + private static void SetChildren(GeometryGroup geometryGroup, GeometryCollection children) + { + geometryGroup.Children.Parent = null; + + children.Parent = geometryGroup; + + geometryGroup.Children = children; + } + protected override IGeometryImpl? CreateDefiningGeometry() { if (_children.Count > 0)