|
1 | 1 | using System.Windows.Media;
|
2 | 2 |
|
3 |
| -namespace MaterialDesignThemes.Wpf |
| 3 | +namespace MaterialDesignThemes.Wpf; |
| 4 | + |
| 5 | +public static class ToggleButtonAssist |
4 | 6 | {
|
5 |
| - public static class ToggleButtonAssist |
6 |
| - { |
7 |
| - private static readonly DependencyPropertyKey HasOnContentPropertyKey = |
8 |
| - DependencyProperty.RegisterAttachedReadOnly( |
9 |
| - "HasOnContent", typeof(bool), typeof(ToggleButtonAssist), |
10 |
| - new PropertyMetadata(false)); |
11 |
| - |
12 |
| - public static readonly DependencyProperty HasOnContentProperty = HasOnContentPropertyKey.DependencyProperty; |
13 |
| - |
14 |
| - private static void SetHasOnContent(DependencyObject element, object value) |
15 |
| - => element.SetValue(HasOnContentPropertyKey, value); |
16 |
| - |
17 |
| - /// <summary> |
18 |
| - /// Framework use only. |
19 |
| - /// </summary> |
20 |
| - /// <param name="element"></param> |
21 |
| - /// <returns></returns> |
22 |
| - public static bool GetHasOnContent(DependencyObject element) |
23 |
| - => (bool)element.GetValue(HasOnContentProperty); |
24 |
| - |
25 |
| - /// <summary> |
26 |
| - /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
27 |
| - /// </summary> |
28 |
| - public static readonly DependencyProperty OnContentProperty = DependencyProperty.RegisterAttached( |
29 |
| - "OnContent", typeof(object), typeof(ToggleButtonAssist), new PropertyMetadata(default(object), OnContentPropertyChangedCallback)); |
30 |
| - |
31 |
| - private static void OnContentPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) |
32 |
| - => SetHasOnContent(dependencyObject, dependencyPropertyChangedEventArgs.NewValue != null); |
33 |
| - |
34 |
| - /// <summary> |
35 |
| - /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
36 |
| - /// </summary> |
37 |
| - /// <param name="element"></param> |
38 |
| - /// <param name="value"></param> |
39 |
| - public static void SetOnContent(DependencyObject element, object value) |
40 |
| - => element.SetValue(OnContentProperty, value); |
41 |
| - |
42 |
| - /// <summary> |
43 |
| - /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
44 |
| - /// </summary> |
45 |
| - public static object GetOnContent(DependencyObject element) |
46 |
| - => element.GetValue(OnContentProperty); |
47 |
| - |
48 |
| - /// <summary> |
49 |
| - /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
50 |
| - /// </summary> |
51 |
| - public static readonly DependencyProperty OnContentTemplateProperty = DependencyProperty.RegisterAttached( |
52 |
| - "OnContentTemplate", typeof(DataTemplate), typeof(ToggleButtonAssist), new PropertyMetadata(default(DataTemplate))); |
53 |
| - |
54 |
| - /// <summary> |
55 |
| - /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
56 |
| - /// </summary> |
57 |
| - public static void SetOnContentTemplate(DependencyObject element, DataTemplate value) |
58 |
| - => element.SetValue(OnContentTemplateProperty, value); |
59 |
| - |
60 |
| - /// <summary> |
61 |
| - /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
62 |
| - /// </summary> |
63 |
| - public static DataTemplate GetOnContentTemplate(DependencyObject element) |
64 |
| - => (DataTemplate)element.GetValue(OnContentTemplateProperty); |
65 |
| - |
66 |
| - public static readonly DependencyProperty SwitchTrackOnBackgroundProperty = |
67 |
| - DependencyProperty.RegisterAttached( |
68 |
| - "SwitchTrackOnBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist)); |
69 |
| - |
70 |
| - public static void SetSwitchTrackOnBackground(DependencyObject element, SolidColorBrush value) |
71 |
| - => element.SetValue(SwitchTrackOnBackgroundProperty, value); |
72 |
| - |
73 |
| - public static SolidColorBrush GetSwitchTrackOnBackground(DependencyObject element) |
74 |
| - => (SolidColorBrush)element.GetValue(SwitchTrackOnBackgroundProperty); |
75 |
| - |
76 |
| - public static readonly DependencyProperty SwitchTrackOffBackgroundProperty = |
77 |
| - DependencyProperty.RegisterAttached( |
78 |
| - "SwitchTrackOffBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist)); |
79 |
| - |
80 |
| - public static void SetSwitchTrackOffBackground(DependencyObject element, SolidColorBrush value) |
81 |
| - => element.SetValue(SwitchTrackOffBackgroundProperty, value); |
82 |
| - |
83 |
| - public static SolidColorBrush GetSwitchTrackOffBackground(DependencyObject element) |
84 |
| - => (SolidColorBrush)element.GetValue(SwitchTrackOffBackgroundProperty); |
85 |
| - } |
| 7 | + private static readonly DependencyPropertyKey HasOnContentPropertyKey = |
| 8 | + DependencyProperty.RegisterAttachedReadOnly( |
| 9 | + "HasOnContent", typeof(bool), typeof(ToggleButtonAssist), |
| 10 | + new PropertyMetadata(false)); |
| 11 | + |
| 12 | + public static readonly DependencyProperty HasOnContentProperty = HasOnContentPropertyKey.DependencyProperty; |
| 13 | + |
| 14 | + private static void SetHasOnContent(DependencyObject element, object value) |
| 15 | + => element.SetValue(HasOnContentPropertyKey, value); |
| 16 | + |
| 17 | + /// <summary> |
| 18 | + /// Framework use only. |
| 19 | + /// </summary> |
| 20 | + /// <param name="element"></param> |
| 21 | + /// <returns></returns> |
| 22 | + public static bool GetHasOnContent(DependencyObject element) |
| 23 | + => (bool)element.GetValue(HasOnContentProperty); |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
| 27 | + /// </summary> |
| 28 | + public static readonly DependencyProperty OnContentProperty = DependencyProperty.RegisterAttached( |
| 29 | + "OnContent", typeof(object), typeof(ToggleButtonAssist), new PropertyMetadata(default(object), OnContentPropertyChangedCallback)); |
| 30 | + |
| 31 | + private static void OnContentPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) |
| 32 | + => SetHasOnContent(dependencyObject, dependencyPropertyChangedEventArgs.NewValue != null); |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
| 36 | + /// </summary> |
| 37 | + /// <param name="element"></param> |
| 38 | + /// <param name="value"></param> |
| 39 | + public static void SetOnContent(DependencyObject element, object value) |
| 40 | + => element.SetValue(OnContentProperty, value); |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles. |
| 44 | + /// </summary> |
| 45 | + public static object GetOnContent(DependencyObject element) |
| 46 | + => element.GetValue(OnContentProperty); |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
| 50 | + /// </summary> |
| 51 | + public static readonly DependencyProperty OnContentTemplateProperty = DependencyProperty.RegisterAttached( |
| 52 | + "OnContentTemplate", typeof(DataTemplate), typeof(ToggleButtonAssist), new PropertyMetadata(default(DataTemplate))); |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
| 56 | + /// </summary> |
| 57 | + public static void SetOnContentTemplate(DependencyObject element, DataTemplate value) |
| 58 | + => element.SetValue(OnContentTemplateProperty, value); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles. |
| 62 | + /// </summary> |
| 63 | + public static DataTemplate GetOnContentTemplate(DependencyObject element) |
| 64 | + => (DataTemplate)element.GetValue(OnContentTemplateProperty); |
| 65 | + |
| 66 | + public static readonly DependencyProperty SwitchTrackOnBackgroundProperty = |
| 67 | + DependencyProperty.RegisterAttached( |
| 68 | + "SwitchTrackOnBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist)); |
| 69 | + |
| 70 | + public static void SetSwitchTrackOnBackground(DependencyObject element, SolidColorBrush value) |
| 71 | + => element.SetValue(SwitchTrackOnBackgroundProperty, value); |
| 72 | + |
| 73 | + public static SolidColorBrush GetSwitchTrackOnBackground(DependencyObject element) |
| 74 | + => (SolidColorBrush)element.GetValue(SwitchTrackOnBackgroundProperty); |
| 75 | + |
| 76 | + public static readonly DependencyProperty SwitchTrackOffBackgroundProperty = |
| 77 | + DependencyProperty.RegisterAttached( |
| 78 | + "SwitchTrackOffBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist)); |
| 79 | + |
| 80 | + public static void SetSwitchTrackOffBackground(DependencyObject element, SolidColorBrush value) |
| 81 | + => element.SetValue(SwitchTrackOffBackgroundProperty, value); |
| 82 | + |
| 83 | + public static SolidColorBrush GetSwitchTrackOffBackground(DependencyObject element) |
| 84 | + => (SolidColorBrush)element.GetValue(SwitchTrackOffBackgroundProperty); |
86 | 85 | }
|
0 commit comments