Skip to content
Closed
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
50 changes: 45 additions & 5 deletions src/Controls/src/Core/CheckBox/CheckBox.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#nullable disable
using System;
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/*" />
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 @@ -16,11 +18,38 @@ 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 is not null && checkBox.Command.CanExecute(checkBox.CommandParameter))
{
checkBox.Command.Execute(checkBox.CommandParameter);
}
Comment on lines +27 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we should be doing here as we are going to fire the CheckChanged event but NOT the command if the command disabled it.

The command can disable the checkbox, and that is fine. But, if the dev then manually sets checked and we only fire one, will that be unexpected? Do we have a place where we have an event and command and we have to do something like this?

I found Button does this:

public static void ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager)
{
	if (visualElement.IsEnabled == true)
	{
		ButtonElementManager.Command?.Execute(ButtonElementManager.CommandParameter);
		ButtonElementManager.PropagateUpClicked(); // <- this is the clicked event
	}
}


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


public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(CheckBox), null, propertyChanging: CommandElement.OnCommandChanging, propertyChanged: CommandElement.OnCommandChanged);

public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(CheckBox), null, propertyChanged: CommandElement.OnCommandParameterChanged);

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 All @@ -44,9 +73,13 @@ public bool IsChecked
protected internal override void ChangeVisualState()
{
if (IsEnabled && IsChecked)
{
VisualStateManager.GoToState(this, IsCheckedVisualState);
}
else
{
base.ChangeVisualState();
}
}

public event EventHandler<CheckedChangedEventArgs> CheckedChanged;
Expand All @@ -72,6 +105,13 @@ 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 @@ -80,4 +120,4 @@ bool ICheckBox.IsChecked
set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.GradientBrush.IsEmpty.get -> bool
override Microsoft.Maui.Controls.Handlers.Compatibility.TableViewModelRenderer.GetItemViewType(int position) -> int
override Microsoft.Maui.Controls.Handlers.Compatibility.TableViewRenderer.OnMeasure(int widthMeasureSpec, int heightMeasureSpec) -> void
Expand Down Expand Up @@ -131,6 +132,10 @@ Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty() -> void
override Microsoft.Maui.Controls.Button.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.ImageButton.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.SearchBar.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.InputView.FontFamily.get -> string
~Microsoft.Maui.Controls.InputView.FontFamily.set -> void
~Microsoft.Maui.Controls.WebView.UserAgent.get -> string
Expand All @@ -142,6 +147,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool
~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAutoScalingEnabledProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.Handlers.Compatibility.CellRenderer.Invoke(string! command, object? args) -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.CellRenderer.UpdateValue(string! property) -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PreferredStatusBarUpdateAnimation.get -> UIKit.UIStatusBarAnimation
Expand Down Expand Up @@ -143,6 +144,10 @@ static Microsoft.Maui.Controls.Shapes.Matrix.operator ==(Microsoft.Maui.Controls
Microsoft.Maui.Controls.DragEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformDragEventArgs?
Microsoft.Maui.Controls.DragStartingEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformDragStartingEventArgs?
Microsoft.Maui.Controls.DropEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformDropEventArgs?
~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.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper) -> void
~Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper, Microsoft.Maui.CommandMapper commandMapper) -> void
override Microsoft.Maui.Controls.View.ChangeVisualState() -> void
Expand All @@ -168,6 +173,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool
~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAutoScalingEnabledProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.Handlers.Compatibility.CellRenderer.Invoke(string! command, object? args) -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.CellRenderer.UpdateValue(string! property) -> void
override Microsoft.Maui.Controls.GradientBrush.IsEmpty.get -> bool
Expand Down Expand Up @@ -139,6 +140,10 @@ static Microsoft.Maui.Controls.Region.operator !=(Microsoft.Maui.Controls.Region
static Microsoft.Maui.Controls.Region.operator ==(Microsoft.Maui.Controls.Region left, Microsoft.Maui.Controls.Region right) -> bool
static Microsoft.Maui.Controls.Shapes.Matrix.operator !=(Microsoft.Maui.Controls.Shapes.Matrix left, Microsoft.Maui.Controls.Shapes.Matrix right) -> bool
static Microsoft.Maui.Controls.Shapes.Matrix.operator ==(Microsoft.Maui.Controls.Shapes.Matrix left, Microsoft.Maui.Controls.Shapes.Matrix right) -> 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.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper) -> void
~Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper, Microsoft.Maui.CommandMapper commandMapper) -> void
override Microsoft.Maui.Controls.View.ChangeVisualState() -> void
Expand All @@ -164,6 +169,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool
~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAutoScalingEnabledProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Microsoft.Maui.Controls.InputView.FontSize.get -> double
Microsoft.Maui.Controls.InputView.FontSize.set -> void
Microsoft.Maui.Controls.InputView.SelectionLength.get -> int
Microsoft.Maui.Controls.InputView.SelectionLength.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.GradientBrush.IsEmpty.get -> bool
override Microsoft.Maui.Controls.Label.ArrangeOverride(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
static Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapTitle(Microsoft.Maui.Controls.Handlers.ShellItemHandler! handler, Microsoft.Maui.Controls.ShellItem! item) -> void
Expand Down Expand Up @@ -128,6 +129,10 @@ static Microsoft.Maui.Controls.Region.operator ==(Microsoft.Maui.Controls.Region
static Microsoft.Maui.Controls.Shapes.Matrix.operator !=(Microsoft.Maui.Controls.Shapes.Matrix left, Microsoft.Maui.Controls.Shapes.Matrix right) -> bool
static Microsoft.Maui.Controls.Shapes.Matrix.operator ==(Microsoft.Maui.Controls.Shapes.Matrix left, Microsoft.Maui.Controls.Shapes.Matrix right) -> bool
virtual Microsoft.Maui.Controls.Handlers.ShellItemHandler.UpdateAppearance(Microsoft.Maui.Controls.IShellAppearanceElement! appearance) -> void
~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.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper) -> void
~Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper, Microsoft.Maui.CommandMapper commandMapper) -> void
override Microsoft.Maui.Controls.View.ChangeVisualState() -> void
Expand All @@ -148,6 +153,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool
~static Microsoft.Maui.Controls.Handlers.ShellHandler.MapFlyoutIcon(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view) -> void
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAutoScalingEnabledProperty -> 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 @@ -51,6 +51,7 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
Microsoft.Maui.Controls.TimeChangedEventArgs
Microsoft.Maui.Controls.TimeChangedEventArgs.NewTime.get -> System.TimeSpan
Microsoft.Maui.Controls.TimeChangedEventArgs.OldTime.get -> System.TimeSpan
Expand Down Expand Up @@ -106,6 +107,10 @@ Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty() -> void
override Microsoft.Maui.Controls.Button.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.ImageButton.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.SearchBar.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.InputView.FontFamily.get -> string
~Microsoft.Maui.Controls.InputView.FontFamily.set -> void
~Microsoft.Maui.Controls.WebView.UserAgent.get -> string
Expand All @@ -117,6 +122,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~static Microsoft.Maui.Controls.RadioButton.MapContent(Microsoft.Maui.Handlers.IRadioButtonHandler handler, Microsoft.Maui.Controls.RadioButton radioButton) -> void
~static Microsoft.Maui.Controls.RadioButton.MapContent(Microsoft.Maui.Handlers.RadioButtonHandler handler, Microsoft.Maui.Controls.RadioButton radioButton) -> void
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.HideSoftInputOnTappedProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool
Microsoft.Maui.Controls.TimeChangedEventArgs
Microsoft.Maui.Controls.TimeChangedEventArgs.NewTime.get -> System.TimeSpan
Microsoft.Maui.Controls.TimeChangedEventArgs.OldTime.get -> System.TimeSpan
Expand Down Expand Up @@ -125,6 +126,10 @@ Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty() -> void
override Microsoft.Maui.Controls.Button.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.ImageButton.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.SearchBar.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.Element.AddLogicalChild(Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.InsertLogicalChild(int index, Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.RemoveLogicalChild(Microsoft.Maui.Controls.Element element) -> bool
Expand All @@ -144,6 +149,8 @@ Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~static Microsoft.Maui.Controls.RadioButton.MapContent(Microsoft.Maui.Handlers.IRadioButtonHandler handler, Microsoft.Maui.Controls.RadioButton radioButton) -> void
~static Microsoft.Maui.Controls.RadioButton.MapContent(Microsoft.Maui.Handlers.RadioButtonHandler handler, Microsoft.Maui.Controls.RadioButton radioButton) -> void
~static Microsoft.Maui.Controls.Region.FromRectangles(System.Collections.Generic.IEnumerable<Microsoft.Maui.Graphics.Rect> rectangles) -> Microsoft.Maui.Controls.Region
~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.InputView.CursorPositionProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.InputView.FontAutoScalingEnabledProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
31 changes: 31 additions & 0 deletions src/Controls/tests/Core.UnitTests/CheckBoxUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,36 @@ public void CheckedVisualStates()
element.IsChecked = false;
Assert.NotEqual(checkedStateName, stateGroup.CurrentState.Name);
}


[Fact]
public void CheckBoxClickWhenCommandCanExecuteFalse()
{
bool invoked = false;
var checkBox = new CheckBox()
{
Command = new Command(() => invoked = true, () => false),
IsChecked = false
};

checkBox.IsChecked = true;

Assert.False(invoked);
}

[Fact]
public void CheckBoxClickWhenCommandCanExecuteTrue()
{
bool invoked = false;
var checkBox = new CheckBox()
{
Command = new Command(() => invoked = true, () => true),
IsChecked = false
};

checkBox.IsChecked = true;

Assert.True(invoked);
}
}
}