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> (
nameof(Children),
o => o.Children,
SetChildren);
(o, v)=> o.Children = v);
public static readonly StyledProperty<FillRule> FillRuleProperty =
AvaloniaProperty.Register<GeometryGroup, FillRule>(nameof(FillRule));
private GeometryCollection _children = new GeometryCollection();
private GeometryCollection _children;
public GeometryGroup()
{
_children = new GeometryCollection
{
Parent = this
};
}
/// <summary>
/// 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()

2
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();

Loading…
Cancel
Save