Browse Source

Moved some properties around.

- Moved Background out of Control. Fixes #14.
- Added Font properties to TemplatedControl.
pull/16/head
Steven Kirk 12 years ago
parent
commit
a9a569557b
  1. 9
      Perspex.Controls/Border.cs
  2. 9
      Perspex.Controls/Control.cs
  3. 6
      Perspex.Controls/Image.cs
  4. 36
      Perspex.Controls/Primitives/TemplatedControl.cs
  5. 9
      Perspex.Controls/TextBlock.cs
  6. 4
      Perspex.Themes.Default/TreeViewItemStyle.cs
  7. 36
      Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs

9
Perspex.Controls/Border.cs

@ -13,12 +13,21 @@ namespace Perspex.Controls
public class Border : Decorator public class Border : Decorator
{ {
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Border, Brush>("Background");
static Border() static Border()
{ {
Control.AffectsRender(Border.BackgroundProperty); Control.AffectsRender(Border.BackgroundProperty);
Control.AffectsRender(Border.BorderBrushProperty); Control.AffectsRender(Border.BorderBrushProperty);
} }
public Brush Background
{
get { return this.GetValue(BackgroundProperty); }
set { this.SetValue(BackgroundProperty, value); }
}
public override void Render(IDrawingContext context) public override void Render(IDrawingContext context)
{ {
Brush background = this.Background; Brush background = this.Background;

9
Perspex.Controls/Control.cs

@ -18,9 +18,6 @@ namespace Perspex.Controls
public class Control : InputElement, IStyleable, IStyleHost public class Control : InputElement, IStyleable, IStyleHost
{ {
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Control, Brush>("Background");
public static readonly PerspexProperty<Brush> BorderBrushProperty = public static readonly PerspexProperty<Brush> BorderBrushProperty =
PerspexProperty.Register<Control, Brush>("BorderBrush"); PerspexProperty.Register<Control, Brush>("BorderBrush");
@ -52,12 +49,6 @@ namespace Perspex.Controls
PseudoClass(InputElement.IsPointerOverProperty, ":pointerover"); PseudoClass(InputElement.IsPointerOverProperty, ":pointerover");
} }
public Brush Background
{
get { return this.GetValue(BackgroundProperty); }
set { this.SetValue(BackgroundProperty, value); }
}
public Brush BorderBrush public Brush BorderBrush
{ {
get { return this.GetValue(BorderBrushProperty); } get { return this.GetValue(BorderBrushProperty); }

6
Perspex.Controls/Image.cs

@ -32,14 +32,8 @@ namespace Perspex.Controls
public override void Render(IDrawingContext drawingContext) public override void Render(IDrawingContext drawingContext)
{ {
Brush background = this.Background;
Bitmap source = this.Source; Bitmap source = this.Source;
if (background != null)
{
drawingContext.FillRectange(background, new Rect(this.ActualSize));
}
if (source != null) if (source != null)
{ {
Rect viewPort = new Rect(this.ActualSize); Rect viewPort = new Rect(this.ActualSize);

36
Perspex.Controls/Primitives/TemplatedControl.cs

@ -14,6 +14,18 @@ namespace Perspex.Controls.Primitives
public class TemplatedControl : Control, ITemplatedControl 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 = public static readonly PerspexProperty<ControlTemplate> TemplateProperty =
PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template"); PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template");
@ -29,6 +41,30 @@ namespace Perspex.Controls.Primitives
}); });
} }
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 public ControlTemplate Template
{ {
get { return this.GetValue(TemplateProperty); } get { return this.GetValue(TemplateProperty); }

9
Perspex.Controls/TextBlock.cs

@ -13,6 +13,9 @@ namespace Perspex.Controls
public class TextBlock : Control public class TextBlock : Control
{ {
public static readonly PerspexProperty<Brush> BackgroundProperty =
Border.BackgroundProperty.AddOwner<TextBlock>();
public static readonly PerspexProperty<string> FontFamilyProperty = public static readonly PerspexProperty<string> FontFamilyProperty =
PerspexProperty.Register<Control, string>("FontFamily", "Segoe UI", inherits: true); PerspexProperty.Register<Control, string>("FontFamily", "Segoe UI", inherits: true);
@ -47,6 +50,12 @@ namespace Perspex.Controls
}); });
} }
public Brush Background
{
get { return this.GetValue(BackgroundProperty); }
set { this.SetValue(BackgroundProperty, value); }
}
public string Text public string Text
{ {
get { return this.GetValue(TextProperty); } get { return this.GetValue(TextProperty); }

4
Perspex.Themes.Default/TreeViewItemStyle.cs

@ -54,7 +54,7 @@ namespace Perspex.Themes.Default
{ {
Setters = new[] 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")) new Style(x => x.OfType<TreeViewItem>().Class(":empty").Template().OfType<ToggleButton>().Class("expander"))
@ -90,7 +90,7 @@ namespace Perspex.Themes.Default
new Border new Border
{ {
Id = "header", Id = "header",
[~ContentPresenter.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty], [~Border.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty],
[Grid.ColumnProperty] = 1, [Grid.ColumnProperty] = 1,
Content = new ContentPresenter Content = new ContentPresenter
{ {

36
Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs

@ -31,11 +31,14 @@ namespace Perspex.Direct2D1.RenderTests.Controls
Padding = new Thickness(20, 8), Padding = new Thickness(20, 8),
Width = 200, Width = 200,
Height = 200, Height = 200,
Content = new Image Content = new Border
{ {
Background = Brushes.Red, Background = Brushes.Red,
Source = this.bitmap, Content = new Image
Stretch = Stretch.None, {
Source = this.bitmap,
Stretch = Stretch.None,
}
} }
}; };
@ -51,11 +54,14 @@ namespace Perspex.Direct2D1.RenderTests.Controls
Padding = new Thickness(20, 8), Padding = new Thickness(20, 8),
Width = 200, Width = 200,
Height = 200, Height = 200,
Content = new Image Content = new Border
{ {
Background = Brushes.Red, Background = Brushes.Red,
Source = this.bitmap, Content = new Image
Stretch = Stretch.Fill, {
Source = this.bitmap,
Stretch = Stretch.Fill,
}
} }
}; };
@ -71,11 +77,14 @@ namespace Perspex.Direct2D1.RenderTests.Controls
Padding = new Thickness(20, 8), Padding = new Thickness(20, 8),
Width = 200, Width = 200,
Height = 200, Height = 200,
Content = new Image Content = new Border
{ {
Background = Brushes.Red, Background = Brushes.Red,
Source = this.bitmap, Content = new Image
Stretch = Stretch.Uniform, {
Source = this.bitmap,
Stretch = Stretch.Uniform,
}
} }
}; };
@ -91,11 +100,14 @@ namespace Perspex.Direct2D1.RenderTests.Controls
Padding = new Thickness(20, 8), Padding = new Thickness(20, 8),
Width = 200, Width = 200,
Height = 200, Height = 200,
Content = new Image Content = new Border
{ {
Background = Brushes.Red, Background = Brushes.Red,
Source = this.bitmap, Content = new Image
Stretch = Stretch.UniformToFill, {
Source = this.bitmap,
Stretch = Stretch.UniformToFill,
}
} }
}; };

Loading…
Cancel
Save