From a9a569557b2e415d93d0309623311dc3cbb29e73 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 17 Dec 2014 19:05:17 +0100 Subject: [PATCH] Moved some properties around. - Moved Background out of Control. Fixes #14. - Added Font properties to TemplatedControl. --- Perspex.Controls/Border.cs | 9 +++++ Perspex.Controls/Control.cs | 9 ----- Perspex.Controls/Image.cs | 6 ---- .../Primitives/TemplatedControl.cs | 36 +++++++++++++++++++ Perspex.Controls/TextBlock.cs | 9 +++++ Perspex.Themes.Default/TreeViewItemStyle.cs | 4 +-- .../Controls/ImageTests.cs | 36 ++++++++++++------- 7 files changed, 80 insertions(+), 29 deletions(-) diff --git a/Perspex.Controls/Border.cs b/Perspex.Controls/Border.cs index 834a162fe27..282dbd94ff2 100644 --- a/Perspex.Controls/Border.cs +++ b/Perspex.Controls/Border.cs @@ -13,12 +13,21 @@ namespace Perspex.Controls public class Border : Decorator { + public static readonly PerspexProperty BackgroundProperty = + PerspexProperty.Register("Background"); + static Border() { Control.AffectsRender(Border.BackgroundProperty); Control.AffectsRender(Border.BorderBrushProperty); } + public Brush Background + { + get { return this.GetValue(BackgroundProperty); } + set { this.SetValue(BackgroundProperty, value); } + } + public override void Render(IDrawingContext context) { Brush background = this.Background; diff --git a/Perspex.Controls/Control.cs b/Perspex.Controls/Control.cs index 3c3f6f795e6..f7b60daf9d5 100644 --- a/Perspex.Controls/Control.cs +++ b/Perspex.Controls/Control.cs @@ -18,9 +18,6 @@ namespace Perspex.Controls public class Control : InputElement, IStyleable, IStyleHost { - public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background"); - public static readonly PerspexProperty BorderBrushProperty = PerspexProperty.Register("BorderBrush"); @@ -52,12 +49,6 @@ static Control() PseudoClass(InputElement.IsPointerOverProperty, ":pointerover"); } - public Brush Background - { - get { return this.GetValue(BackgroundProperty); } - set { this.SetValue(BackgroundProperty, value); } - } - public Brush BorderBrush { get { return this.GetValue(BorderBrushProperty); } diff --git a/Perspex.Controls/Image.cs b/Perspex.Controls/Image.cs index d63a0958d87..dab6bb1bc17 100644 --- a/Perspex.Controls/Image.cs +++ b/Perspex.Controls/Image.cs @@ -32,14 +32,8 @@ public Stretch Stretch public override void Render(IDrawingContext drawingContext) { - Brush background = this.Background; Bitmap source = this.Source; - if (background != null) - { - drawingContext.FillRectange(background, new Rect(this.ActualSize)); - } - if (source != null) { Rect viewPort = new Rect(this.ActualSize); diff --git a/Perspex.Controls/Primitives/TemplatedControl.cs b/Perspex.Controls/Primitives/TemplatedControl.cs index bce7b5e4abf..29752b7049e 100644 --- a/Perspex.Controls/Primitives/TemplatedControl.cs +++ b/Perspex.Controls/Primitives/TemplatedControl.cs @@ -14,6 +14,18 @@ namespace Perspex.Controls.Primitives public class TemplatedControl : Control, ITemplatedControl { + public static readonly PerspexProperty BackgroundProperty = + Border.BackgroundProperty.AddOwner(); + + public static readonly PerspexProperty FontFamilyProperty = + TextBlock.FontFamilyProperty.AddOwner(); + + public static readonly PerspexProperty FontSizeProperty = + TextBlock.FontSizeProperty.AddOwner(); + + public static readonly PerspexProperty FontStyleProperty = + TextBlock.FontStyleProperty.AddOwner(); + public static readonly PerspexProperty TemplateProperty = PerspexProperty.Register("Template"); @@ -29,6 +41,30 @@ static TemplatedControl() }); } + public Brush Background + { + get { return this.GetValue(BackgroundProperty); } + set { this.SetValue(BackgroundProperty, value); } + } + + public string FontFamily + { + get { return this.GetValue(FontFamilyProperty); } + set { this.SetValue(FontFamilyProperty, value); } + } + + public double FontSize + { + get { return this.GetValue(FontSizeProperty); } + set { this.SetValue(FontSizeProperty, value); } + } + + public FontStyle FontStyle + { + get { return this.GetValue(FontStyleProperty); } + set { this.SetValue(FontStyleProperty, value); } + } + public ControlTemplate Template { get { return this.GetValue(TemplateProperty); } diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index a62a55e1d79..b24f26f9e73 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -13,6 +13,9 @@ namespace Perspex.Controls public class TextBlock : Control { + public static readonly PerspexProperty BackgroundProperty = + Border.BackgroundProperty.AddOwner(); + public static readonly PerspexProperty FontFamilyProperty = PerspexProperty.Register("FontFamily", "Segoe UI", inherits: true); @@ -47,6 +50,12 @@ public TextBlock() }); } + public Brush Background + { + get { return this.GetValue(BackgroundProperty); } + set { this.SetValue(BackgroundProperty, value); } + } + public string Text { get { return this.GetValue(TextProperty); } diff --git a/Perspex.Themes.Default/TreeViewItemStyle.cs b/Perspex.Themes.Default/TreeViewItemStyle.cs index 5f4d7695384..b1123ce262f 100644 --- a/Perspex.Themes.Default/TreeViewItemStyle.cs +++ b/Perspex.Themes.Default/TreeViewItemStyle.cs @@ -54,7 +54,7 @@ public TreeViewItemStyle() { Setters = new[] { - new Setter(ToggleButton.RenderTransformProperty, new RotateTransform(90)), + new Setter(ToggleButton.RenderTransformProperty, new RotateTransform(45)), }, }, new Style(x => x.OfType().Class(":empty").Template().OfType().Class("expander")) @@ -90,7 +90,7 @@ private Control Template(TreeViewItem control) new Border { Id = "header", - [~ContentPresenter.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty], + [~Border.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty], [Grid.ColumnProperty] = 1, Content = new ContentPresenter { diff --git a/Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs b/Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs index 83f0c601a66..77e952bbd1d 100644 --- a/Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs +++ b/Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs @@ -31,11 +31,14 @@ public void Image_Stretch_None() Padding = new Thickness(20, 8), Width = 200, Height = 200, - Content = new Image + Content = new Border { Background = Brushes.Red, - Source = this.bitmap, - Stretch = Stretch.None, + Content = new Image + { + Source = this.bitmap, + Stretch = Stretch.None, + } } }; @@ -51,11 +54,14 @@ public void Image_Stretch_Fill() Padding = new Thickness(20, 8), Width = 200, Height = 200, - Content = new Image + Content = new Border { Background = Brushes.Red, - Source = this.bitmap, - Stretch = Stretch.Fill, + Content = new Image + { + Source = this.bitmap, + Stretch = Stretch.Fill, + } } }; @@ -71,11 +77,14 @@ public void Image_Stretch_Uniform() Padding = new Thickness(20, 8), Width = 200, Height = 200, - Content = new Image + Content = new Border { Background = Brushes.Red, - Source = this.bitmap, - Stretch = Stretch.Uniform, + Content = new Image + { + Source = this.bitmap, + Stretch = Stretch.Uniform, + } } }; @@ -91,11 +100,14 @@ public void Image_Stretch_UniformToFill() Padding = new Thickness(20, 8), Width = 200, Height = 200, - Content = new Image + Content = new Border { Background = Brushes.Red, - Source = this.bitmap, - Stretch = Stretch.UniformToFill, + Content = new Image + { + Source = this.bitmap, + Stretch = Stretch.UniformToFill, + } } };