Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions src/Controls/src/Core/CheckBox/CheckBox.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#nullable disable
using System;
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="Type[@FullName='Microsoft.Maui.Controls.CheckBox']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
[ElementHandler<CheckBoxHandler>]
public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement, ICheckBox
public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement, ICheckBox, ICommandElement
{
readonly Lazy<PlatformConfigurationRegistry<CheckBox>> _platformConfigurationRegistry;
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="//Member[@MemberName='IsCheckedVisualState']/Docs/*" />
Expand All @@ -19,11 +21,45 @@ public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderEl
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();
if (bindable is not CheckBox checkBox)
{
return;
}

checkBox.Handler?.UpdateValue(nameof(ICheckBox.Foreground));
checkBox.CheckedChanged?.Invoke(bindable, new CheckedChangedEventArgs((bool)newValue));
if (checkBox.Command?.CanExecute(checkBox.CommandParameter) == true)
{
checkBox.Command.Execute(checkBox.CommandParameter);
}

checkBox.ChangeVisualState();
}, defaultBindingMode: BindingMode.TwoWay);

/// <summary>Bindable property for the <see cref="Command"/> property.</summary>
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(CheckBox), null, propertyChanging: CommandElement.OnCommandChanging, propertyChanged: CommandElement.OnCommandChanged);

/// <summary>Bindable property for the <see cref="CommandParameter"/> property.</summary>
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(CheckBox), null, propertyChanged: CommandElement.OnCommandParameterChanged);

/// <summary>
/// Gets or sets the command that is executed when the CheckBox is checked or unchecked. This is a bindable property.
/// </summary>
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

/// <summary>
/// Gets or sets the parameter to pass to the <see cref="Command"/> when it is executed. This is a bindable property.
/// </summary>
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}

/// <summary>Bindable property for <see cref="Color"/>.</summary>
public static readonly BindableProperty ColorProperty = ColorElement.ColorProperty;

Expand Down Expand Up @@ -105,6 +141,11 @@ void IBorderElement.OnBorderColorPropertyChanged(Color oldValue, Color newValue)
bool IBorderElement.IsBackgroundSet() => IsSet(BackgroundProperty);
bool IBorderElement.IsBorderColorSet() => false;
bool IBorderElement.IsBorderWidthSet() => false;
void ICommandElement.CanExecuteChanged(object sender, EventArgs e) =>
RefreshIsEnabledProperty();

protected override bool IsEnabledCore =>
base.IsEnabledCore && CommandElement.GetCanExecute(this);
public Paint Foreground => Color?.AsPaint();

bool ICheckBox.IsChecked
Expand All @@ -113,6 +154,12 @@ bool ICheckBox.IsChecked
set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler);
}

ICommand ICommandElement.Command => Command;

object ICommandElement.CommandParameter => CommandParameter;

WeakCommandSubscription ICommandElement.CleanupTracker { get; set; }

private protected override string GetDebuggerDisplay()
{
return $"{base.GetDebuggerDisplay()}, IsChecked = {IsChecked}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void
Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -450,6 +455,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void
Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -430,6 +435,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void
Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -430,6 +435,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const Microsoft.Maui.Controls.BrushTypeConverter.Rgb = "rgb" -> string!
const Microsoft.Maui.Controls.BrushTypeConverter.Rgba = "rgba" -> string!
Microsoft.Maui.Controls.BrushTypeConverter.GradientBrushParser.GradientBrushParser(Microsoft.Maui.Graphics.Converters.ColorTypeConverter? colorConverter = null) -> void
Microsoft.Maui.Controls.BrushTypeConverter.GradientBrushParser.Parse(string? css) -> Microsoft.Maui.Controls.GradientBrush?
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -94,6 +99,8 @@ Microsoft.Maui.Controls.Xaml.Internals.AllowImplicitXmlnsDeclarationAttribute.Al
*REMOVED*~static Microsoft.Maui.Controls.MenuItem.GetAccelerator(Microsoft.Maui.Controls.BindableObject bindable) -> Microsoft.Maui.Controls.Accelerator
*REMOVED*~static Microsoft.Maui.Controls.MenuItem.SetAccelerator(Microsoft.Maui.Controls.BindableObject bindable, Microsoft.Maui.Controls.Accelerator value) -> void
*REMOVED*~static readonly Microsoft.Maui.Controls.MenuItem.AcceleratorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
override Microsoft.Maui.Controls.BrushTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
override Microsoft.Maui.Controls.BrushTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
override Microsoft.Maui.Controls.BrushTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void
Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -441,6 +446,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
7 changes: 7 additions & 0 deletions src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void
Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
Microsoft.Maui.Controls.ContentView.SafeAreaEdges.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime oldDate, System.DateTime newDate) -> void
Microsoft.Maui.Controls.DateChangedEventArgs.DateChangedEventArgs(System.DateTime? oldDate, System.DateTime? newDate) -> void
*REMOVED*Microsoft.Maui.Controls.DateChangedEventArgs.NewDate.get -> System.DateTime
Expand Down Expand Up @@ -412,6 +417,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea
Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void
Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool
Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.CheckBox.Command.set -> void
~Microsoft.Maui.Controls.CheckBox.CommandParameter.get -> object
~Microsoft.Maui.Controls.CheckBox.CommandParameter.set -> void
~Microsoft.Maui.Controls.ContentPresenter.Children.get -> System.Collections.Generic.IReadOnlyList<Microsoft.Maui.Controls.Element>
~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void
Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness
Expand Down Expand Up @@ -412,6 +417,8 @@ static readonly Microsoft.Maui.Controls.Border.SafeAreaEdgesProperty -> Microsof
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static readonly Microsoft.Maui.Controls.ClickGestureRecognizer.NumberOfClicksRequiredProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.CheckBox.CommandProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPage.SafeAreaEdgesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparentProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ContentPresenter.PaddingProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Loading
Loading