From fe432c00047d0249f94ffd329d9949de4c6f4419 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Thu, 27 Nov 2025 11:33:19 +0000 Subject: [PATCH 1/2] Added new kb article cancel-checkbox-change-net-maui --- .../cancel-checkbox-change-net-maui.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 knowledge-base/cancel-checkbox-change-net-maui.md diff --git a/knowledge-base/cancel-checkbox-change-net-maui.md b/knowledge-base/cancel-checkbox-change-net-maui.md new file mode 100644 index 000000000..c6a5aec29 --- /dev/null +++ b/knowledge-base/cancel-checkbox-change-net-maui.md @@ -0,0 +1,96 @@ +--- +title: Cancel Checkbox Change in .NET MAUI +description: Learn how to cancel a Checkbox change in .NET MAUI using the IsCheckedChanged event. +type: how-to +page_title: Prevent Checkbox State Change in .NET MAUI +meta_title: Prevent Checkbox State Change in .NET MAUI +slug: cancel-checkbox-change-net-maui +tags: checkbox, .net maui, ischeckedchanged, ischecked, binding +res_type: kb +--- + +## Environment + +| Version | Product | Author | +| --- | --- | ---- | +| 12.0.0 | Telerik UI for .NET MAUI CheckBox | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | + +## Description + +I want to cancel a state change in a Checkbox control in .NET MAUI based on a specific condition. This allows me to maintain control over the Checkbox's state and update it dynamically. + +This knowledge base article also answers the following questions: +- How to prevent Checkbox state change in .NET MAUI? +- How to handle the `IsCheckedChanged` event to cancel state change? +- How to implement conditional logic for Checkbox state in .NET MAUI? + +## Solution + +To achieve this behavior, use the `IsCheckedChanged` event and set the `IsChecked` property conditionally. + +**1.** Create a `ViewModel` class to store and bind the Checkbox state. + +```csharp +public class ViewModel : NotifyPropertyChangedBase +{ + private bool myproperty = false; + public bool MyProperty + { + get => this.myproperty; + set + { + if (this.myproperty != value) + { + this.myproperty = value; + OnPropertyChanged(); + } + } + } +} +``` + +**2.** Use the `IsCheckedChanged` event to monitor state changes. + +**3.** Implement conditional logic to revert the state if a condition is not met. + +```csharp +public partial class MainPage : ContentPage +{ + ViewModel vm; + public bool OperationPassed = true; + + public MainPage() + { + InitializeComponent(); + this.vm = new ViewModel(); + this.BindingContext = this.vm; + } + + private void RadCheckBox_IsCheckedChanged(object sender, IsCheckedChangedEventArgs e) + { + // Check condition and revert state + if (this.OperationPassed is false) + { + this.vm.MyProperty = false; + } + else + { + this.vm.MyProperty = true; + } + } +} +``` + +**4.** The Checkbox definition in XAML: + +```xml + + + +``` + +## See Also + +- [CheckBox Overview](https://www.telerik.com/maui-ui/documentation/controls/checkbox/overview) From 2f6de849fb9422d100ea5c67d0ad4e90d3c75b2c Mon Sep 17 00:00:00 2001 From: Didi Yordanova <39412212+didiyordanova@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:45:28 +0200 Subject: [PATCH 2/2] Update cancel-checkbox-change-net-maui.md --- knowledge-base/cancel-checkbox-change-net-maui.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge-base/cancel-checkbox-change-net-maui.md b/knowledge-base/cancel-checkbox-change-net-maui.md index c6a5aec29..2fd07a1d4 100644 --- a/knowledge-base/cancel-checkbox-change-net-maui.md +++ b/knowledge-base/cancel-checkbox-change-net-maui.md @@ -81,7 +81,7 @@ public partial class MainPage : ContentPage } ``` -**4.** The Checkbox definition in XAML: +**4.** Define the CheckBox in XAML: ```xml