Events in .NET MAUI CheckBox

StateChanged event

This event occurs when the value or state of the IsChecked property is changed by touching the check box or setting the value to the IsChecked property using XAML or C# code. The event arguments are of type StateChangedEventArgs and expose the following property:

<syncfusion:SfCheckBox x:Name="checkBox" Text="Unchecked State" IsThreeState="True" StateChanged="CheckBox_StateChanged"/>
SfCheckBox checkBox = new SfCheckBox();
checkBox.Text = "Unchecked State";
checkBox.IsThreeState = true;
checkBox.StateChanged += CheckBox_StateChanged;
this.Content = checkBox;
private void CheckBox_StateChanged(object sender, Syncfusion.Maui.Buttons.StateChangedEventArgs e)
{
    if (e.IsChecked.HasValue && e.IsChecked.Value)
    {
        checkBox.Text = "Checked State";
    }
    else if(e.IsChecked.HasValue && !e.IsChecked.Value)
    {
        checkBox.Text = "Unchecked State";
    }
    else
    {
    checkBox.Text = "Indeterminate State";
    }
}

.NET MAUI CheckBox

StateChanging event

The StateChanging event is triggered when the state of the IsChecked property is about to change by tapping the CheckBox control. The event arguments are of type StateChangingEventArgs and provide the following properties:

  • IsChecked : The new value(state) of the IsChecked property.
  • Cancel : Gets or sets a value indicating whether the event should be canceled.
<syncfusion:SfCheckBox x:Name="checkBox" Text="CheckBox" StateChanging="OnStateChanging"/>
SfCheckBox checkBox = new SfCheckBox();
checkBox.Text = "CheckBox";
checkBox.StateChanging += OnStateChanging;
this.Content = checkBox;
private void OnStateChanging(object sender, StateChangingEventArgs e)
{
    e.cancel=true;
}