From cf25bed2cfc9cb0178c74576498bc5d07109615e Mon Sep 17 00:00:00 2001 From: timunie <47110241+timunie@users.noreply.github.com> Date: Sun, 16 Jun 2019 19:22:57 +0200 Subject: [PATCH] (GH-3136) Introduce CheckBoxHelper A CheckBoxHelper was introdiuced to allow different Glyphs for different Styles --- .../Controls/Helper/CheckBoxHelper.cs | 199 ++++++++++++++++++ .../Styles/Controls.CheckBox.xaml | 110 +++++++--- 2 files changed, 282 insertions(+), 27 deletions(-) create mode 100644 src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs diff --git a/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs b/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs new file mode 100644 index 0000000000..5b15bf76e6 --- /dev/null +++ b/src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs @@ -0,0 +1,199 @@ +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)); + + public static double GetCheckBoxSize(DependencyObject obj) + { + return (double)obj.GetValue(CheckBoxSizeProperty); + } + + 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()); + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetCheckedGlyph(DependencyObject obj) + { + return (object)obj.GetValue(CheckedGlyphProperty); + } + + [Category(AppName.MahApps)] + public static void SetCheckedGlyph(DependencyObject obj, object value) + { + obj.SetValue(CheckedGlyphProperty, value); + } + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetCheckedBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(CheckedBackgroundBrushProperty); + } + + public static void SetCheckedBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(CheckedBackgroundBrushProperty, value); + } + + + public static DataTemplate GetCheckedGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(CheckedGlyphTemplateProperty); + } + + public static void SetCheckedGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(CheckedGlyphTemplateProperty, value); + } + + public static Brush GetCheckedBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(CheckedBorderBrushProperty); + } + + 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()); + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetUnCheckedGlyph(DependencyObject obj) + { + return (object)obj.GetValue(UnCheckedGlyphProperty); + } + + [Category(AppName.MahApps)] + public static void SetUnCheckedGlyph(DependencyObject obj, object value) + { + obj.SetValue(UnCheckedGlyphProperty, value); + } + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetUnCheckedBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(UnCheckedBackgroundBrushProperty); + } + + public static void SetUnCheckedBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(UnCheckedBackgroundBrushProperty, value); + } + + + public static DataTemplate GetUnCheckedGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(UnCheckedGlyphTemplateProperty); + } + + public static void SetUnCheckedGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(UnCheckedGlyphTemplateProperty, value); + } + + public static Brush GetUnCheckedBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(UnCheckedBorderBrushProperty); + } + + 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()); + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static object GetIntermediateGlyph(DependencyObject obj) + { + return (object)obj.GetValue(IntermediateGlyphProperty); + } + + [Category(AppName.MahApps)] + public static void SetIntermediateGlyph(DependencyObject obj, object value) + { + obj.SetValue(IntermediateGlyphProperty, value); + } + + + [AttachedPropertyBrowsableForType(typeof(CheckBox))] + public static Brush GetIntermediateBackgroundBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(IntermediateBackgroundBrushProperty); + } + + public static void SetIntermediateBackgroundBrush(DependencyObject obj, Brush value) + { + obj.SetValue(IntermediateBackgroundBrushProperty, value); + } + + + public static DataTemplate GetIntermediateGlyphTemplate(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(IntermediateGlyphTemplateProperty); + } + + public static void SetIntermediateGlyphTemplate(DependencyObject obj, DataTemplate value) + { + obj.SetValue(IntermediateGlyphTemplateProperty, value); + } + + public static Brush GetIntermediateBorderBrush(DependencyObject obj) + { + return (Brush)obj.GetValue(IntermediateBorderBrushProperty); + } + + 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 b3a9015354..8865c7c073 100644 --- a/src/MahApps.Metro/Styles/Controls.CheckBox.xaml +++ b/src/MahApps.Metro/Styles/Controls.CheckBox.xaml @@ -5,7 +5,12 @@ +