-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
CheckBox.cs
83 lines (71 loc) · 3.36 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
#nullable disable
using System;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="Type[@FullName='Microsoft.Maui.Controls.CheckBox']/Docs/*" />
public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement, ICheckBox
{
readonly Lazy<PlatformConfigurationRegistry<CheckBox>> _platformConfigurationRegistry;
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="//Member[@MemberName='IsCheckedVisualState']/Docs/*" />
public const string IsCheckedVisualState = "IsChecked";
/// <summary>Bindable property for <see cref="IsChecked"/>.</summary>
public static readonly BindableProperty IsCheckedProperty =
BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false,
propertyChanged: (bindable, oldValue, newValue) =>
{
((CheckBox)bindable).Handler?.UpdateValue(nameof(ICheckBox.Foreground));
((CheckBox)bindable).CheckedChanged?.Invoke(bindable, new CheckedChangedEventArgs((bool)newValue));
((CheckBox)bindable).ChangeVisualState();
}, defaultBindingMode: BindingMode.TwoWay);
/// <summary>Bindable property for <see cref="Color"/>.</summary>
public static readonly BindableProperty ColorProperty = ColorElement.ColorProperty;
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="//Member[@MemberName='Color']/Docs/*" />
public Color Color
{
get => (Color)GetValue(ColorProperty);
set => SetValue(ColorProperty, value);
}
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="//Member[@MemberName='.ctor']/Docs/*" />
public CheckBox() => _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<CheckBox>>(() => new PlatformConfigurationRegistry<CheckBox>(this));
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="//Member[@MemberName='IsChecked']/Docs/*" />
public bool IsChecked
{
get => (bool)GetValue(IsCheckedProperty);
set => SetValue(IsCheckedProperty, value);
}
protected internal override void ChangeVisualState()
{
if (IsEnabled && IsChecked)
VisualStateManager.GoToState(this, IsCheckedVisualState);
else
base.ChangeVisualState();
}
public event EventHandler<CheckedChangedEventArgs> CheckedChanged;
/// <inheritdoc/>
public IPlatformElementConfiguration<T, CheckBox> On<T>() where T : IConfigPlatform
{
return _platformConfigurationRegistry.Value.On<T>();
}
void IBorderElement.OnBorderColorPropertyChanged(Color oldValue, Color newValue)
{
}
Color IBorderElement.BorderColor => Colors.Transparent;
int IBorderElement.CornerRadius => 0;
double IBorderElement.BorderWidth => 0;
int IBorderElement.CornerRadiusDefaultValue => 0;
Color IBorderElement.BorderColorDefaultValue => Colors.Transparent;
double IBorderElement.BorderWidthDefaultValue => 0;
bool IBorderElement.IsCornerRadiusSet() => false;
bool IBorderElement.IsBackgroundColorSet() => IsSet(BackgroundColorProperty);
bool IBorderElement.IsBackgroundSet() => IsSet(BackgroundProperty);
bool IBorderElement.IsBorderColorSet() => false;
bool IBorderElement.IsBorderWidthSet() => false;
public Paint Foreground => Color?.AsPaint();
bool ICheckBox.IsChecked
{
get => IsChecked;
set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler);
}
}
}