Skip to content

Commit

Permalink
(MahAppsGH-3136) Introduce new Windows 10 CheckBox Style
Browse files Browse the repository at this point in the history
Introduced a new CheckBox Style that switches the colors for a better visibility, especially with a dark theme
  • Loading branch information
timunie authored and punker76 committed Sep 2, 2019
1 parent fabd465 commit 16f4cd5
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
<CheckBox Margin="{StaticResource ControlMargin}"
Content="Enabled"
IsChecked="{x:Null}"
IsThreeState="True" />
IsThreeState="True"
Style="{StaticResource MahApps.Metro.Styles.CheckBox.Win10}"/>
<CheckBox Margin="{StaticResource ControlMargin}"
Content="Disabled"
IsEnabled="False" />
Expand Down
126 changes: 121 additions & 5 deletions src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ 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);
Expand All @@ -34,46 +44,82 @@ public static void SetCheckBoxSize(DependencyObject obj, double value)
public static readonly DependencyProperty CheckedBorderBrushProperty = DependencyProperty.RegisterAttached("CheckedBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata());


/// <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);
}


/// <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);
}


/// <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);
}

/// <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);
Expand All @@ -90,46 +136,82 @@ public static void SetCheckedBorderBrush(DependencyObject obj, Brush value)
public static readonly DependencyProperty UnCheckedBorderBrushProperty = DependencyProperty.RegisterAttached("UnCheckedBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata());


/// <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);
}


/// <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);
}


/// <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);
}

/// <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);
Expand All @@ -146,54 +228,88 @@ public static void SetUnCheckedBorderBrush(DependencyObject obj, Brush value)
public static readonly DependencyProperty IntermediateBorderBrushProperty = DependencyProperty.RegisterAttached("IntermediateBorderBrush", typeof(Brush), typeof(CheckBoxHelper), new FrameworkPropertyMetadata());


/// <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);
}


/// <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);
}


/// <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);
}

/// <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



}
}
24 changes: 24 additions & 0 deletions src/MahApps.Metro/Converters/DoubleToGridLengthConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace MahApps.Metro.Converters
{
public class DoubleToGridLengthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new GridLength((double)value, GridUnitType.Pixel);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 16f4cd5

Please sign in to comment.