16 changed files with 307 additions and 105 deletions
@ -0,0 +1,12 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="CheckBox.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls |
|||
{ |
|||
public class CheckBox : ToggleButton |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ToggleButton.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls |
|||
{ |
|||
using System; |
|||
|
|||
public class ToggleButton : Button |
|||
{ |
|||
public static readonly PerspexProperty<bool> IsCheckedProperty = |
|||
PerspexProperty.Register<ToggleButton, bool>("IsChecked"); |
|||
|
|||
public ToggleButton() |
|||
{ |
|||
this.Click += (s, e) => this.IsChecked = !this.IsChecked; |
|||
|
|||
this.GetObservable(IsCheckedProperty).Subscribe(x => |
|||
{ |
|||
if (x) |
|||
{ |
|||
this.Classes.Add(":checked"); |
|||
} |
|||
else |
|||
{ |
|||
this.Classes.Remove(":checked"); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public bool IsChecked |
|||
{ |
|||
get { return this.GetValue(IsCheckedProperty); } |
|||
set { this.SetValue(IsCheckedProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ButtonStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class CheckBoxStyle : Styles |
|||
{ |
|||
public CheckBoxStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<CheckBox>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<CheckBox>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<CheckBox>().Template().Id("checkMark")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TextBlock.VisibilityProperty, Visibility.Hidden), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<CheckBox>().Class(":checked").Template().Id("checkMark")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TextBlock.VisibilityProperty, Visibility.Visible), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(CheckBox control) |
|||
{ |
|||
Border result = new Border |
|||
{ |
|||
Content = new StackPanel |
|||
{ |
|||
Orientation = Orientation.Horizontal, |
|||
Gap = 8, |
|||
Children = new PerspexList<Control> |
|||
{ |
|||
new Border |
|||
{ |
|||
BorderThickness = 2.0, |
|||
BorderBrush = new SolidColorBrush(0xff000000), |
|||
Padding = new Thickness(2), |
|||
Content = new TextBlock |
|||
{ |
|||
Id = "checkMark", |
|||
Text = "Y", |
|||
Background = null, |
|||
}, |
|||
}, |
|||
new ContentPresenter |
|||
{ |
|||
}, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
result.TemplateBinding(control, Border.BackgroundProperty); |
|||
StackPanel stack = (StackPanel)result.Content; |
|||
ContentPresenter cp = (ContentPresenter)stack.Children[1]; |
|||
cp.TemplateBinding(control, ContentPresenter.ContentProperty); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue