Browse Source

Bind button templates to button properties.

pull/4/head
grokys 12 years ago
parent
commit
51a94ea8f3
  1. 27
      Perspex/Controls/Border.cs
  2. 6
      Perspex/Controls/Button.cs
  3. 28
      Perspex/Controls/Control.cs
  4. 3
      TestApplication/Program.cs

27
Perspex/Controls/Border.cs

@ -5,33 +5,6 @@
public class Border : Decorator public class Border : Decorator
{ {
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Border, Brush>("Background");
public static readonly PerspexProperty<Brush> BorderBrushProperty =
PerspexProperty.Register<Border, Brush>("BorderBrush");
public static readonly PerspexProperty<double> BorderThicknessProperty =
PerspexProperty.Register<Border, double>("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) public override void Render(IDrawingContext context)
{ {
Brush background = this.Background; Brush background = this.Background;

6
Perspex/Controls/Button.cs

@ -11,9 +11,9 @@ namespace Perspex.Controls
protected override Visual DefaultTemplate() protected override Visual DefaultTemplate()
{ {
Border border = new Border(); Border border = new Border();
border.Background = new Perspex.Media.SolidColorBrush(0xff808080); border.Bind(Border.BackgroundProperty, this.GetObservable(BackgroundProperty));
border.BorderBrush = new Perspex.Media.SolidColorBrush(0xff000000); border.Bind(Border.BorderBrushProperty, this.GetObservable(BorderBrushProperty));
border.BorderThickness = 2; border.Bind(Border.BorderThicknessProperty, this.GetObservable(BorderThicknessProperty));
border.Padding = new Thickness(3); border.Padding = new Thickness(3);
ContentPresenter contentPresenter = new ContentPresenter(); ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(ContentProperty)); contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(ContentProperty));

28
Perspex/Controls/Control.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using Perspex.Layout; using Perspex.Layout;
using Perspex.Media;
public enum HorizontalAlignment public enum HorizontalAlignment
{ {
@ -22,6 +23,15 @@
public abstract class Control : Visual, ILayoutable public abstract class Control : Visual, ILayoutable
{ {
public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Border, Brush>("Background");
public static readonly PerspexProperty<Brush> BorderBrushProperty =
PerspexProperty.Register<Border, Brush>("BorderBrush");
public static readonly PerspexProperty<double> BorderThicknessProperty =
PerspexProperty.Register<Border, double>("BorderThickness");
public static readonly PerspexProperty<HorizontalAlignment> HorizontalAlignmentProperty = public static readonly PerspexProperty<HorizontalAlignment> HorizontalAlignmentProperty =
PerspexProperty.Register<Control, HorizontalAlignment>("HorizontalAlignment"); PerspexProperty.Register<Control, HorizontalAlignment>("HorizontalAlignment");
@ -31,6 +41,24 @@
public static readonly PerspexProperty<Thickness> MarginProperty = public static readonly PerspexProperty<Thickness> MarginProperty =
PerspexProperty.Register<Control, Thickness>("Margin"); PerspexProperty.Register<Control, Thickness>("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 public Size? DesiredSize
{ {
get; get;

3
TestApplication/Program.cs

@ -26,6 +26,9 @@ namespace TestApplication
Content = "Hello World", Content = "Hello World",
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
Background = new SolidColorBrush(0xff808080),
BorderThickness = 2,
BorderBrush = new SolidColorBrush(0xff000000),
}; };
window.Show(); window.Show();

Loading…
Cancel
Save