A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

98 lines
3.6 KiB

// -----------------------------------------------------------------------
// <copyright file="RadioButtonStyle.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Themes.Default
{
using System;
using System.Linq;
using Perspex.Controls;
using Perspex.Layout;
using Perspex.Media;
using Perspex.Controls.Shapes;
using Perspex.Styling;
using Perspex.Controls.Presenters;
public class RadioButtonStyle : Styles
{
public RadioButtonStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<RadioButton>())
{
Setters = new[]
{
new Setter(Button.TemplateProperty, ControlTemplate.Create<RadioButton>(this.Template)),
},
},
new Style(x => x.OfType<RadioButton>().Template().Name("checkMark"))
{
Setters = new[]
{
new Setter(Shape.IsVisibleProperty, false),
},
},
new Style(x => x.OfType<RadioButton>().Class(":checked").Template().Name("checkMark"))
{
Setters = new[]
{
new Setter(Shape.IsVisibleProperty, true),
},
},
});
}
private Control Template(RadioButton control)
{
Border result = new Border
{
[~Border.BackgroundProperty] = control[~RadioButton.BackgroundProperty],
Content = new Grid
{
ColumnDefinitions = new ColumnDefinitions
{
new ColumnDefinition(GridLength.Auto),
new ColumnDefinition(new GridLength(1, GridUnitType.Star)),
},
Children = new Controls
{
new Ellipse
{
Name = "checkBorder",
Stroke = Brushes.Black,
StrokeThickness = 2,
Width = 18,
Height = 18,
VerticalAlignment = VerticalAlignment.Center,
[Grid.ColumnProperty] = 0,
},
new Ellipse
{
Name = "checkMark",
Fill = Brushes.Black,
Width = 10,
Height = 10,
Stretch = Stretch.Uniform,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
[Grid.ColumnProperty] = 0,
},
new ContentPresenter
{
Name = "contentPresenter",
Margin = new Thickness(4, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center,
[~ContentPresenter.ContentProperty] = control[~RadioButton.ContentProperty],
[Grid.ColumnProperty] = 1,
},
},
},
};
return result;
}
}
}