Browse Source

FIx GeometryGroup.Children parent handling

pull/8326/head
Benedikt Stebner 4 years ago
parent
commit
9cfac4dd3f
  1. 23
      src/Avalonia.Base/Media/GeometryGroup.cs
  2. 2
      tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs

23
src/Avalonia.Base/Media/GeometryGroup.cs

@ -14,12 +14,20 @@ namespace Avalonia.Media
AvaloniaProperty.RegisterDirect<GeometryGroup, GeometryCollection> ( AvaloniaProperty.RegisterDirect<GeometryGroup, GeometryCollection> (
nameof(Children), nameof(Children),
o => o.Children, o => o.Children,
SetChildren); (o, v)=> o.Children = v);
public static readonly StyledProperty<FillRule> FillRuleProperty = public static readonly StyledProperty<FillRule> FillRuleProperty =
AvaloniaProperty.Register<GeometryGroup, FillRule>(nameof(FillRule)); AvaloniaProperty.Register<GeometryGroup, FillRule>(nameof(FillRule));
private GeometryCollection _children = new GeometryCollection(); private GeometryCollection _children;
public GeometryGroup()
{
_children = new GeometryCollection
{
Parent = this
};
}
/// <summary> /// <summary>
/// Gets or sets the collection that contains the child geometries. /// Gets or sets the collection that contains the child geometries.
@ -30,7 +38,8 @@ namespace Avalonia.Media
get => _children; get => _children;
set set
{ {
SetAndRaise(ChildrenProperty, ref _children, value); OnChildrenChanged(_children, value);
SetAndRaise(ChildrenProperty, ref _children, value);
} }
} }
@ -56,13 +65,11 @@ namespace Avalonia.Media
return result; return result;
} }
private static void SetChildren(GeometryGroup geometryGroup, GeometryCollection children) protected void OnChildrenChanged(GeometryCollection oldChildren, GeometryCollection newChildren)
{ {
geometryGroup.Children.Parent = null; oldChildren.Parent = null;
children.Parent = geometryGroup;
geometryGroup.Children = children; newChildren.Parent = this;
} }
protected override IGeometryImpl? CreateDefiningGeometry() protected override IGeometryImpl? CreateDefiningGeometry()

2
tests/Avalonia.Base.UnitTests/Media/GeometryGroupTests.cs

@ -24,7 +24,7 @@ namespace Avalonia.Visuals.UnitTests.Media
} }
[Fact] [Fact]
public void Childrend_Change_Should_Raise_Changed() public void Children_Change_Should_Raise_Changed()
{ {
var target = new GeometryGroup(); var target = new GeometryGroup();

Loading…
Cancel
Save