From 65d701ffa9e2dea4f7c4c4a26bbc18d1e7f76a6d Mon Sep 17 00:00:00 2001 From: grokys Date: Wed, 5 Feb 2014 01:17:34 +0100 Subject: [PATCH] Moved Parent property to visual. Visuals have parents too. --- Perspex/Controls/ContentControl.cs | 14 +++++++++----- Perspex/Controls/Control.cs | 12 ------------ Perspex/Visual.cs | 25 +++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Perspex/Controls/ContentControl.cs b/Perspex/Controls/ContentControl.cs index adefd89cfc..0c2fe58a57 100644 --- a/Perspex/Controls/ContentControl.cs +++ b/Perspex/Controls/ContentControl.cs @@ -19,13 +19,17 @@ namespace Perspex.Controls { this.GetObservable(ContentProperty).Subscribe(x => { - Visual visual = x as Visual; - Control control = x as Control; + IVisual visual = x as IVisual; + ILogical logical = x as ILogical; - if (control != null) + if (visual != null) { - ((IVisual)control).VisualParent = this; - control.SetValue(ParentPropertyRW, this); + visual.VisualParent = this; + } + + if (logical != null) + { + logical.LogicalParent = this; } }); } diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index d149c8f4c4..474bc858a6 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -34,9 +34,6 @@ namespace Perspex.Controls public abstract class Control : Interactive, ILayoutable, IStyleable { - public static readonly ReadOnlyPerspexProperty ParentProperty = - new ReadOnlyPerspexProperty(ParentPropertyRW); - public static readonly PerspexProperty BackgroundProperty = PerspexProperty.Register("Background", inherits: true); @@ -67,9 +64,6 @@ namespace Perspex.Controls public static readonly RoutedEvent MouseLeftButtonUpEvent = RoutedEvent.Register("MouseLeftButtonUp", RoutingStrategy.Bubble); - internal static readonly PerspexProperty ParentPropertyRW = - PerspexProperty.Register("Parent"); - private Classes classes; private string id; @@ -219,12 +213,6 @@ namespace Perspex.Controls set { this.SetValue(MarginProperty, value); } } - public Control Parent - { - get { return this.GetValue(ParentPropertyRW); } - internal set { this.SetValue(ParentPropertyRW, value); } - } - public Styles Styles { get diff --git a/Perspex/Visual.cs b/Perspex/Visual.cs index 805bc51467..f00e98a09f 100644 --- a/Perspex/Visual.cs +++ b/Perspex/Visual.cs @@ -10,10 +10,17 @@ namespace Perspex using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; + using Perspex.Controls; using Perspex.Media; public abstract class Visual : PerspexObject, IVisual, ILogical { + public static readonly ReadOnlyPerspexProperty ParentProperty = + new ReadOnlyPerspexProperty(ParentPropertyRW); + + internal static readonly PerspexProperty ParentPropertyRW = + PerspexProperty.Register("Parent"); + private ILogical logicalParent; private IVisual visualParent; @@ -24,10 +31,24 @@ namespace Perspex protected set; } + public Control Parent + { + get { return this.GetValue(ParentPropertyRW); } + protected set { this.SetValue(ParentPropertyRW, value); } + } + ILogical ILogical.LogicalParent { - get { return this.logicalParent; } - set { this.logicalParent = value; } + get + { + return this.logicalParent; + } + + set + { + this.logicalParent = value; + this.Parent = value as Control; + } } IEnumerable ILogical.LogicalChildren