From 4ca80d4ec81340c72d541e33612d471e445d3460 Mon Sep 17 00:00:00 2001 From: grokys Date: Sat, 1 Feb 2014 17:49:58 +0100 Subject: [PATCH] Started adding a styling system. --- Perspex/Controls/ContentControl.cs | 14 +++++ Perspex/Controls/Control.cs | 74 +++++++++++++++++++++++--- Perspex/Perspex.csproj | 3 ++ Perspex/PerspexObject.cs | 83 ++++++++++++++++++++++++++++-- Perspex/Selectors.cs | 21 ++++++++ Perspex/Setter.cs | 38 ++++++++++++++ Perspex/Style.cs | 67 ++++++++++++++++++++++++ TestApplication/Program.cs | 35 +++++++++---- 8 files changed, 315 insertions(+), 20 deletions(-) create mode 100644 Perspex/Selectors.cs create mode 100644 Perspex/Setter.cs create mode 100644 Perspex/Style.cs 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