From 3e533db93e8c8a054e4e267f33c53bb08139d815 Mon Sep 17 00:00:00 2001 From: punker76 Date: Tue, 8 Oct 2019 10:27:01 +0200 Subject: [PATCH] (GH-3136) Introduce CheckBoxHelper and new Windows 10 CheckBox Style - 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 --- .../ExampleViews/ButtonsExample.xaml | 6 +- .../Controls/Helper/CheckBoxHelper.cs | 315 ++++++++++++++++++ .../Styles/Controls.CheckBox.xaml | 169 ++++++++-- 3 files changed, 457 insertions(+), 33 deletions(-) create mode 100644 src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml index 901b6f2a8f..5c3a9c1040 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml @@ -350,11 +350,13 @@ + IsChecked="True" + IsThreeState="True" /> + IsThreeState="True" + Style="{StaticResource MahApps.Styles.CheckBox.Win10}" /> diff --git a/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs b/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs new file mode 100644 index 0000000000..575392c746 --- /dev/null +++ b/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs @@ -0,0 +1,315 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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)); + + /// + /// Gets the size of the CheckBox itself. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static double GetCheckBoxSize(DependencyObject obj) + { + return (double)obj.GetValue(CheckBoxSizeProperty); + } + + /// + /// Sets the size of the CheckBox itself. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetCheckBoxSize(DependencyObject obj, double value) + { + obj.SetValue(CheckBoxSizeProperty, value); + } + + + #region Checked + // Using a DependencyProperty as the backing store for CheckedGlyph. This enables animation, styling, binding, etc... + public static readonly DependencyProperty CheckedGlyphProperty = DependencyProperty.RegisterAttached("CheckedGlyph", typeof(object), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty CheckedGlyphTemplateProperty = DependencyProperty.RegisterAttached("CheckedGlyphTemplate", typeof(DataTemplate), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty CheckedBackgroundBrushProperty = DependencyProperty.RegisterAttached("CheckedBackgroundBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty CheckedBorderBrushProperty = DependencyProperty.RegisterAttached("CheckedBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + + + /// + /// Gets the the Glyph for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetCheckedGlyph(DependencyObject obj) + { + return (object)obj.GetValue(CheckedGlyphProperty); + } + + /// + /// Sets the the Glyph for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetCheckedGlyph(DependencyObject obj, object value) + { + obj.SetValue(CheckedGlyphProperty, value); + } + + + /// + /// Gets the the Background for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetCheckedBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(CheckedBackgroundBrushProperty); + } + + /// + /// Sets the the Background for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetCheckedBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(CheckedBackgroundBrushProperty, value); + } + + /// + /// Gets the the GlyphTemplate for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static DataTemplate GetCheckedGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(CheckedGlyphTemplateProperty); + } + + /// + /// Sets the the GlyphTemplate for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetCheckedGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(CheckedGlyphTemplateProperty, value); + } + + /// + /// Gets the the BorderBrush for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetCheckedBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(CheckedBorderBrushProperty); + } + + /// + /// Sets the the BorderBrush for IsChecked = true. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetCheckedBorderBrush(DependencyObject obj, Brush value) + { + obj.SetValue(CheckedBorderBrushProperty, value); + } + + #endregion + + + #region UnChecked + // Using a DependencyProperty as the backing store for UnCheckedGlyph. This enables animation, styling, binding, etc... + public static readonly DependencyProperty UnCheckedGlyphProperty = DependencyProperty.RegisterAttached("UnCheckedGlyph", typeof(object), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty UnCheckedGlyphTemplateProperty = DependencyProperty.RegisterAttached("UnCheckedGlyphTemplate", typeof(DataTemplate), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty UnCheckedBackgroundBrushProperty = DependencyProperty.RegisterAttached("UnCheckedBackgroundBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty UnCheckedBorderBrushProperty = DependencyProperty.RegisterAttached("UnCheckedBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + + + /// + /// Gets the the Glyph for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetUnCheckedGlyph(DependencyObject obj) + { + return (object)obj.GetValue(UnCheckedGlyphProperty); + } + + /// + /// Sets the the Glyph for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetUnCheckedGlyph(DependencyObject obj, object value) + { + obj.SetValue(UnCheckedGlyphProperty, value); + } + + + /// + /// Gets the the BackgroundBrush for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetUnCheckedBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(UnCheckedBackgroundBrushProperty); + } + + /// + /// Sets the the BackgroundBrush for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetUnCheckedBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(UnCheckedBackgroundBrushProperty, value); + } + + /// + /// Gets the the GlyphTemplate for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static DataTemplate GetUnCheckedGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(UnCheckedGlyphTemplateProperty); + } + + /// + /// Sets the the GlyphTemplate for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetUnCheckedGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(UnCheckedGlyphTemplateProperty, value); + } + + /// + /// Gets the the BorderBrush for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetUnCheckedBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(UnCheckedBorderBrushProperty); + } + + /// + /// Sets the the BorderBrush for IsChecked = false. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetUnCheckedBorderBrush(DependencyObject obj, Brush value) + { + obj.SetValue(UnCheckedBorderBrushProperty, value); + } + + #endregion + + + #region Intermediate + // Using a DependencyProperty as the backing store for IntermediateGlyph. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IntermediateGlyphProperty = DependencyProperty.RegisterAttached("IntermediateGlyph", typeof(object), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty IntermediateGlyphTemplateProperty = DependencyProperty.RegisterAttached("IntermediateGlyphTemplate", typeof(DataTemplate), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty IntermediateBackgroundBrushProperty = DependencyProperty.RegisterAttached("IntermediateBackgroundBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + public static readonly DependencyProperty IntermediateBorderBrushProperty = DependencyProperty.RegisterAttached("IntermediateBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata()); + + + /// + /// Gets the the Glyph for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetIntermediateGlyph(DependencyObject obj) + { + return (object)obj.GetValue(IntermediateGlyphProperty); + } + + /// + /// Sets the the Glyph for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetIntermediateGlyph(DependencyObject obj, object value) + { + obj.SetValue(IntermediateGlyphProperty, value); + } + + + /// + /// Gets the the BackgroundBrush for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetIntermediateBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(IntermediateBackgroundBrushProperty); + } + + /// + /// Sets the the BackgroundBrush for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetIntermediateBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(IntermediateBackgroundBrushProperty, value); + } + + /// + /// Gets the the GlyphTemplate for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static DataTemplate GetIntermediateGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(IntermediateGlyphTemplateProperty); + } + + /// + /// Sets the the GlyphTemplate for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetIntermediateGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(IntermediateGlyphTemplateProperty, value); + } + + /// + /// Gets the the BorderBrush for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetIntermediateBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(IntermediateBorderBrushProperty); + } + + /// + /// Sets the the BorderBrush for IsChecked = null. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static void SetIntermediateBorderBrush(DependencyObject obj, Brush value) + { + obj.SetValue(IntermediateBorderBrushProperty, value); + } + + #endregion + + } +} diff --git a/src/MahApps.Metro/Styles/Controls.CheckBox.xaml b/src/MahApps.Metro/Styles/Controls.CheckBox.xaml index 7a57f169c9..4a121697b2 100644 --- a/src/MahApps.Metro/Styles/Controls.CheckBox.xaml +++ b/src/MahApps.Metro/Styles/Controls.CheckBox.xaml @@ -5,9 +5,35 @@ + +