Skip to content

Commit

Permalink
Moved some properties around.
Browse files Browse the repository at this point in the history
- Moved Background out of Control. Fixes #14.
- Added Font properties to TemplatedControl.
  • Loading branch information
Steven Kirk committed Dec 17, 2014
1 parent df88c7a commit a9a5695
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 29 deletions.
9 changes: 9 additions & 0 deletions Perspex.Controls/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ namespace Perspex.Controls

public class Border : Decorator
{
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Border, Brush>("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;
Expand Down
9 changes: 0 additions & 9 deletions Perspex.Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ namespace Perspex.Controls

public class Control : InputElement, IStyleable, IStyleHost
{
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Control, Brush>("Background");

public static readonly PerspexProperty<Brush> BorderBrushProperty =
PerspexProperty.Register<Control, Brush>("BorderBrush");

Expand Down Expand Up @@ -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); }
Expand Down
6 changes: 0 additions & 6 deletions Perspex.Controls/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions Perspex.Controls/Primitives/TemplatedControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ namespace Perspex.Controls.Primitives

public class TemplatedControl : Control, ITemplatedControl
{
public static readonly PerspexProperty<Brush> BackgroundProperty =
Border.BackgroundProperty.AddOwner<TemplatedControl>();

public static readonly PerspexProperty<string> FontFamilyProperty =
TextBlock.FontFamilyProperty.AddOwner<TemplatedControl>();

public static readonly PerspexProperty<double> FontSizeProperty =
TextBlock.FontSizeProperty.AddOwner<TemplatedControl>();

public static readonly PerspexProperty<FontStyle> FontStyleProperty =
TextBlock.FontStyleProperty.AddOwner<TemplatedControl>();

public static readonly PerspexProperty<ControlTemplate> TemplateProperty =
PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template");

Expand All @@ -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); }
Expand Down
9 changes: 9 additions & 0 deletions Perspex.Controls/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Perspex.Controls

public class TextBlock : Control
{
public static readonly PerspexProperty<Brush> BackgroundProperty =
Border.BackgroundProperty.AddOwner<TextBlock>();

public static readonly PerspexProperty<string> FontFamilyProperty =
PerspexProperty.Register<Control, string>("FontFamily", "Segoe UI", inherits: true);

Expand Down Expand Up @@ -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); }
Expand Down
4 changes: 2 additions & 2 deletions Perspex.Themes.Default/TreeViewItemStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeViewItem>().Class(":empty").Template().OfType<ToggleButton>().Class("expander"))
Expand Down Expand Up @@ -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
{
Expand Down
36 changes: 24 additions & 12 deletions Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
};

Expand All @@ -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,
}
}
};

Expand All @@ -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,
}
}
};

Expand All @@ -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,
}
}
};

Expand Down

0 comments on commit a9a5695

Please sign in to comment.