-
Notifications
You must be signed in to change notification settings - Fork 262
/
RadioButtonToggle.cs
44 lines (42 loc) · 1.24 KB
/
RadioButtonToggle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Windows;
using System.Windows.Controls;
namespace TFT_Overlay
{
public class OptionalRadioButton : RadioButton
{
#region bool IsOptional dependency property
public static DependencyProperty IsOptionalProperty =
DependencyProperty.Register(
"IsOptional",
typeof(bool),
typeof(OptionalRadioButton),
new PropertyMetadata((bool)true,
(obj, args) =>
{
((OptionalRadioButton)obj).OnIsOptionalChanged(args);
}));
public bool IsOptional
{
get
{
return (bool)GetValue(IsOptionalProperty);
}
set
{
SetValue(IsOptionalProperty, value);
}
}
private void OnIsOptionalChanged(DependencyPropertyChangedEventArgs args)
{
// TODO: Add event handler if needed
}
#endregion
protected override void OnClick()
{
bool? wasChecked = this.IsChecked;
base.OnClick();
if (this.IsOptional && wasChecked == true)
this.IsChecked = false;
}
}
}