From 51a94ea8f3523ff7415f1750bfa2267e234f003d Mon Sep 17 00:00:00 2001 From: grokys Date: Fri, 20 Dec 2013 02:12:51 +0100 Subject: [PATCH] Bind button templates to button properties. --- Perspex/Controls/Border.cs | 27 --------------------------- Perspex/Controls/Button.cs | 6 +++--- Perspex/Controls/Control.cs | 28 ++++++++++++++++++++++++++++ TestApplication/Program.cs | 3 +++ 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs index 78a3ba8fe7..74e30eb51b 100644 --- a/Perspex/Controls/Border.cs +++ b/Perspex/Controls/Border.cs @@ -5,33 +5,6 @@ public class Border : Decorator { - public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background"); - - public static readonly PerspexProperty BorderBrushProperty = - PerspexProperty.Register("BorderBrush"); - - public static readonly PerspexProperty BorderThicknessProperty = - PerspexProperty.Register("BorderThickness"); - - public Brush Background - { - get { return this.GetValue(BackgroundProperty); } - set { this.SetValue(BackgroundProperty, value); } - } - - public Brush BorderBrush - { - get { return this.GetValue(BorderBrushProperty); } - set { this.SetValue(BorderBrushProperty, value); } - } - - public double BorderThickness - { - get { return this.GetValue(BorderThicknessProperty); } - set { this.SetValue(BorderThicknessProperty, value); } - } - public override void Render(IDrawingContext context) { Brush background = this.Background; diff --git a/Perspex/Controls/Button.cs b/Perspex/Controls/Button.cs index 85126b762b..9afb22c4ab 100644 --- a/Perspex/Controls/Button.cs +++ b/Perspex/Controls/Button.cs @@ -11,9 +11,9 @@ namespace Perspex.Controls protected override Visual DefaultTemplate() { Border border = new Border(); - border.Background = new Perspex.Media.SolidColorBrush(0xff808080); - border.BorderBrush = new Perspex.Media.SolidColorBrush(0xff000000); - border.BorderThickness = 2; + border.Bind(Border.BackgroundProperty, this.GetObservable(BackgroundProperty)); + border.Bind(Border.BorderBrushProperty, this.GetObservable(BorderBrushProperty)); + border.Bind(Border.BorderThicknessProperty, this.GetObservable(BorderThicknessProperty)); border.Padding = new Thickness(3); ContentPresenter contentPresenter = new ContentPresenter(); contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(ContentProperty)); diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index 5d3c9eb22c..884837c2d1 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics.Contracts; using Perspex.Layout; + using Perspex.Media; public enum HorizontalAlignment { @@ -22,6 +23,15 @@ public abstract class Control : Visual, ILayoutable { + public static readonly PerspexProperty BackgroundProperty = + PerspexProperty.Register("Background"); + + public static readonly PerspexProperty BorderBrushProperty = + PerspexProperty.Register("BorderBrush"); + + public static readonly PerspexProperty BorderThicknessProperty = + PerspexProperty.Register("BorderThickness"); + public static readonly PerspexProperty HorizontalAlignmentProperty = PerspexProperty.Register("HorizontalAlignment"); @@ -31,6 +41,24 @@ public static readonly PerspexProperty MarginProperty = PerspexProperty.Register("Margin"); + public Brush Background + { + get { return this.GetValue(BackgroundProperty); } + set { this.SetValue(BackgroundProperty, value); } + } + + public Brush BorderBrush + { + get { return this.GetValue(BorderBrushProperty); } + set { this.SetValue(BorderBrushProperty, value); } + } + + public double BorderThickness + { + get { return this.GetValue(BorderThicknessProperty); } + set { this.SetValue(BorderThicknessProperty, value); } + } + public Size? DesiredSize { get; diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index eec8d192f8..724391d53d 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -26,6 +26,9 @@ namespace TestApplication Content = "Hello World", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, + Background = new SolidColorBrush(0xff808080), + BorderThickness = 2, + BorderBrush = new SolidColorBrush(0xff000000), }; window.Show();