/
CheckBox.cs
84 lines (64 loc) · 2.34 KB
/
CheckBox.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using Xamarin.Forms.Platform;
namespace Xamarin.Forms
{
[RenderWith(typeof(_CheckBoxRenderer))]
public class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement
{
public const string IsCheckedVisualState = "IsChecked";
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, propertyChanged: (bindable, oldValue, newValue) =>
{
((CheckBox)bindable).CheckedChanged?.Invoke(bindable, new CheckedChangedEventArgs((bool)newValue));
((CheckBox)bindable).ChangeVisualState();
}, defaultBindingMode: BindingMode.TwoWay);
public static readonly BindableProperty ColorProperty = ColorElement.ColorProperty;
public Color Color
{
get { return (Color)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
readonly Lazy<PlatformConfigurationRegistry<CheckBox>> _platformConfigurationRegistry;
public CheckBox()
{
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<CheckBox>>(() => new PlatformConfigurationRegistry<CheckBox>(this));
}
public bool IsChecked
{
get { return (bool)GetValue(IsCheckedProperty); }
set
{
SetValue(IsCheckedProperty, value);
ChangeVisualState();
}
}
protected internal override void ChangeVisualState()
{
if (IsEnabled && IsChecked)
{
VisualStateManager.GoToState(this, IsCheckedVisualState);
}
else
{
base.ChangeVisualState();
}
}
public event EventHandler<CheckedChangedEventArgs> CheckedChanged;
public IPlatformElementConfiguration<T, CheckBox> On<T>() where T : IConfigPlatform
{
return _platformConfigurationRegistry.Value.On<T>();
}
void IBorderElement.OnBorderColorPropertyChanged(Color oldValue, Color newValue)
{
}
Color IBorderElement.BorderColor => Color.Transparent;
int IBorderElement.CornerRadius => 0;
double IBorderElement.BorderWidth => 0;
int IBorderElement.CornerRadiusDefaultValue => 0;
Color IBorderElement.BorderColorDefaultValue => Color.Transparent;
double IBorderElement.BorderWidthDefaultValue => 0;
bool IBorderElement.IsCornerRadiusSet() => false;
bool IBorderElement.IsBackgroundColorSet() => IsSet(BackgroundColorProperty);
bool IBorderElement.IsBorderColorSet() => false;
bool IBorderElement.IsBorderWidthSet() => false;
}
}