Skip to content

Commit

Permalink
(GH-3136) Introduce CheckBoxHelper and new Windows 10 CheckBox Style
Browse files Browse the repository at this point in the history
- A CheckBoxHelper was introduced to allow different Glyphs and Brushes for different Styles
- Introduced a new Windows 10 CheckBox Style that switches the colors for a better visibility, especially with a dark theme
	- Use Win10 check glyph Xaml path data from "Segoe MDL2 Assets"
	- Set Win10 BorderThickness to 2

Code format
  • Loading branch information
punker76 committed Dec 28, 2019
1 parent 2547185 commit bcf949e
Show file tree
Hide file tree
Showing 3 changed files with 515 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,13 @@
<CheckBox Margin="{StaticResource ControlMargin}" Content="_Enabled" />
<CheckBox Margin="{StaticResource ControlMargin}"
Content="Enabled"
IsChecked="True" />
IsChecked="True"
IsThreeState="True" />
<CheckBox Margin="{StaticResource ControlMargin}"
Content="Enabled"
IsChecked="{x:Null}"
IsThreeState="True" />
IsThreeState="True"
Style="{StaticResource MahApps.Styles.CheckBox.Win10}" />
<CheckBox Margin="{StaticResource ControlMargin}"
Content="Disabled"
IsEnabled="False" />
Expand Down
373 changes: 373 additions & 0 deletions src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,373 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MahApps.Metro.Controls
{
public static class CheckBoxHelper
{
public static readonly DependencyProperty CheckBoxSizeProperty
= DependencyProperty.RegisterAttached(
"CheckBoxSize",
typeof(double),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(18.0));

/// <summary>
/// Gets the size of the CheckBox itself.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static double GetCheckBoxSize(DependencyObject obj)
{
return (double)obj.GetValue(CheckBoxSizeProperty);
}

/// <summary>
/// Sets the size of the CheckBox itself.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckBoxSize(DependencyObject obj, double value)
{
obj.SetValue(CheckBoxSizeProperty, value);
}

#region Checked

public static readonly DependencyProperty CheckedGlyphProperty
= DependencyProperty.RegisterAttached(
"CheckedGlyph",
typeof(object),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(null));

/// <summary>
/// Gets the the Glyph for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static object GetCheckedGlyph(DependencyObject obj)
{
return (object)obj.GetValue(CheckedGlyphProperty);
}

/// <summary>
/// Sets the the Glyph for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckedGlyph(DependencyObject obj, object value)
{
obj.SetValue(CheckedGlyphProperty, value);
}

public static readonly DependencyProperty CheckedGlyphTemplateProperty
= DependencyProperty.RegisterAttached(
"CheckedGlyphTemplate",
typeof(DataTemplate),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(DataTemplate)));

/// <summary>
/// Gets the the GlyphTemplate for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static DataTemplate GetCheckedGlyphTemplate(DependencyObject obj)
{
return (DataTemplate)obj.GetValue(CheckedGlyphTemplateProperty);
}

/// <summary>
/// Sets the the GlyphTemplate for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckedGlyphTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(CheckedGlyphTemplateProperty, value);
}

public static readonly DependencyProperty CheckedBackgroundBrushProperty
= DependencyProperty.RegisterAttached(
"CheckedBackgroundBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the Background for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetCheckedBackgroundBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(CheckedBackgroundBrushProperty);
}

/// <summary>
/// Sets the the Background for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckedBackgroundBrush(DependencyObject obj, Brush value)
{
obj.SetValue(CheckedBackgroundBrushProperty, value);
}

public static readonly DependencyProperty CheckedBorderBrushProperty
= DependencyProperty.RegisterAttached(
"CheckedBorderBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the BorderBrush for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetCheckedBorderBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(CheckedBorderBrushProperty);
}

/// <summary>
/// Sets the the BorderBrush for IsChecked = true.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckedBorderBrush(DependencyObject obj, Brush value)
{
obj.SetValue(CheckedBorderBrushProperty, value);
}

#endregion

#region UnChecked

public static readonly DependencyProperty UnCheckedGlyphProperty
= DependencyProperty.RegisterAttached(
"UnCheckedGlyph",
typeof(object),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(null));

/// <summary>
/// Gets the the Glyph for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static object GetUnCheckedGlyph(DependencyObject obj)
{
return (object)obj.GetValue(UnCheckedGlyphProperty);
}

/// <summary>
/// Sets the the Glyph for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetUnCheckedGlyph(DependencyObject obj, object value)
{
obj.SetValue(UnCheckedGlyphProperty, value);
}

public static readonly DependencyProperty UnCheckedGlyphTemplateProperty
= DependencyProperty.RegisterAttached(
"UnCheckedGlyphTemplate",
typeof(DataTemplate),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(DataTemplate)));

/// <summary>
/// Gets the the GlyphTemplate for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static DataTemplate GetUnCheckedGlyphTemplate(DependencyObject obj)
{
return (DataTemplate)obj.GetValue(UnCheckedGlyphTemplateProperty);
}

/// <summary>
/// Sets the the GlyphTemplate for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetUnCheckedGlyphTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(UnCheckedGlyphTemplateProperty, value);
}

public static readonly DependencyProperty UnCheckedBackgroundBrushProperty
= DependencyProperty.RegisterAttached(
"UnCheckedBackgroundBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the BackgroundBrush for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetUnCheckedBackgroundBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(UnCheckedBackgroundBrushProperty);
}

/// <summary>
/// Sets the the BackgroundBrush for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetUnCheckedBackgroundBrush(DependencyObject obj, Brush value)
{
obj.SetValue(UnCheckedBackgroundBrushProperty, value);
}

public static readonly DependencyProperty UnCheckedBorderBrushProperty
= DependencyProperty.RegisterAttached(
"UnCheckedBorderBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the BorderBrush for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetUnCheckedBorderBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(UnCheckedBorderBrushProperty);
}

/// <summary>
/// Sets the the BorderBrush for IsChecked = false.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetUnCheckedBorderBrush(DependencyObject obj, Brush value)
{
obj.SetValue(UnCheckedBorderBrushProperty, value);
}

#endregion

#region Intermediate

public static readonly DependencyProperty IntermediateGlyphProperty
= DependencyProperty.RegisterAttached(
"IntermediateGlyph",
typeof(object),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(null));

/// <summary>
/// Gets the the Glyph for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static object GetIntermediateGlyph(DependencyObject obj)
{
return (object)obj.GetValue(IntermediateGlyphProperty);
}

/// <summary>
/// Sets the the Glyph for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetIntermediateGlyph(DependencyObject obj, object value)
{
obj.SetValue(IntermediateGlyphProperty, value);
}

public static readonly DependencyProperty IntermediateGlyphTemplateProperty
= DependencyProperty.RegisterAttached(
"IntermediateGlyphTemplate",
typeof(DataTemplate),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(DataTemplate)));

/// <summary>
/// Gets the the GlyphTemplate for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static DataTemplate GetIntermediateGlyphTemplate(DependencyObject obj)
{
return (DataTemplate)obj.GetValue(IntermediateGlyphTemplateProperty);
}

/// <summary>
/// Sets the the GlyphTemplate for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetIntermediateGlyphTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(IntermediateGlyphTemplateProperty, value);
}

public static readonly DependencyProperty IntermediateBackgroundBrushProperty
= DependencyProperty.RegisterAttached(
"IntermediateBackgroundBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the BackgroundBrush for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetIntermediateBackgroundBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(IntermediateBackgroundBrushProperty);
}

/// <summary>
/// Sets the the BackgroundBrush for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetIntermediateBackgroundBrush(DependencyObject obj, Brush value)
{
obj.SetValue(IntermediateBackgroundBrushProperty, value);
}

public static readonly DependencyProperty IntermediateBorderBrushProperty
= DependencyProperty.RegisterAttached(
"IntermediateBorderBrush",
typeof(Brush),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(default(Brush)));

/// <summary>
/// Gets the the BorderBrush for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static Brush GetIntermediateBorderBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(IntermediateBorderBrushProperty);
}

/// <summary>
/// Sets the the BorderBrush for IsChecked = null.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetIntermediateBorderBrush(DependencyObject obj, Brush value)
{
obj.SetValue(IntermediateBorderBrushProperty, value);
}

#endregion
}
}
Loading

0 comments on commit bcf949e

Please sign in to comment.