Browse Source

Make VisualParent a direct PerspexProperty.

pull/223/head
Steven Kirk 11 years ago
parent
commit
b5b750123d
  1. 10
      src/Perspex.SceneGraph/Visual.cs
  2. 16
      tests/Perspex.SceneGraph.UnitTests/VisualTests.cs

10
src/Perspex.SceneGraph/Visual.cs

@ -64,6 +64,12 @@ namespace Perspex
public static readonly PerspexProperty<RelativePoint> TransformOriginProperty =
PerspexProperty.Register<Visual, RelativePoint>(nameof(TransformOrigin), defaultValue: RelativePoint.Center);
/// <summary>
/// Defines the <see cref="IVisual.VisualParent"/> property.
/// </summary>
public static readonly PerspexProperty<IVisual> VisualParentProperty =
PerspexProperty.RegisterDirect<Visual, IVisual>("VisualParent", o => o._visualParent);
/// <summary>
/// Defines the <see cref="ZIndex"/> property.
/// </summary>
@ -83,7 +89,7 @@ namespace Perspex
/// <summary>
/// Holds the parent of the visual.
/// </summary>
private Visual _visualParent;
private IVisual _visualParent;
/// <summary>
/// Whether the element is attached to the visual tree.
@ -444,6 +450,8 @@ namespace Perspex
{
NotifyAttachedToVisualTree(newRoot);
}
RaisePropertyChanged(VisualParentProperty, old, value, BindingPriority.LocalValue);
}
}

16
tests/Perspex.SceneGraph.UnitTests/VisualTests.cs

@ -1,6 +1,8 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Perspex.VisualTree;
using Xunit;
@ -31,6 +33,20 @@ namespace Perspex.SceneGraph.UnitTests
Assert.Equal(target, child.InheritanceParent);
}
[Fact]
public void Added_Child_Should_Notify_VisualParent_Changed()
{
var target = new TestVisual();
var child = new TestVisual();
var parents = new List<IVisual>();
child.GetObservable(Visual.VisualParentProperty).Subscribe(x => parents.Add(x));
target.AddChild(child);
target.RemoveChild(child);
Assert.Equal(new IVisual[] { null, target, null }, parents);
}
[Fact]
public void Removed_Child_Should_Have_VisualParent_Cleared()
{

Loading…
Cancel
Save