diff --git a/Perspex/Controls/ContentControl.cs b/Perspex/Controls/ContentControl.cs index 8fc311d3ea..5c60e4402a 100644 --- a/Perspex/Controls/ContentControl.cs +++ b/Perspex/Controls/ContentControl.cs @@ -1,5 +1,6 @@ namespace Perspex.Controls { + using System; using System.Linq; public abstract class ContentControl : TemplatedControl @@ -7,6 +8,19 @@ public static readonly PerspexProperty ContentProperty = PerspexProperty.Register("Content"); + public ContentControl() + { + this.GetObservable(ContentProperty).Subscribe(x => + { + Control control = x as Control; + + if (control != null) + { + control.SetValue(ParentPropertyRW, this); + } + }); + } + public object Content { get { return this.GetValue(ContentProperty); } diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index 884837c2d1..0d99008821 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -1,9 +1,11 @@ namespace Perspex.Controls { using System; - using System.Diagnostics.Contracts; - using Perspex.Layout; - using Perspex.Media; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics.Contracts; +using Perspex.Layout; +using Perspex.Media; public enum HorizontalAlignment { @@ -23,14 +25,20 @@ public abstract class Control : Visual, ILayoutable { + internal static readonly PerspexProperty ParentPropertyRW = + PerspexProperty.Register("Parent"); + + public static readonly ReadOnlyPerspexProperty ParentProperty = + new ReadOnlyPerspexProperty(ParentPropertyRW); + public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background"); + PerspexProperty.Register("Background"); public static readonly PerspexProperty BorderBrushProperty = - PerspexProperty.Register("BorderBrush"); + PerspexProperty.Register("BorderBrush"); public static readonly PerspexProperty BorderThicknessProperty = - PerspexProperty.Register("BorderThickness"); + PerspexProperty.Register("BorderThickness"); public static readonly PerspexProperty HorizontalAlignmentProperty = PerspexProperty.Register("HorizontalAlignment"); @@ -41,6 +49,13 @@ public static readonly PerspexProperty MarginProperty = PerspexProperty.Register("Margin"); + public Control() + { + this.Classes = new ObservableCollection(); + this.Styles = new ObservableCollection