How to set checkbox.isChecked without raising event How to set checkbox.isChecked without raising event wpf wpf

How to set checkbox.isChecked without raising event


One way would be to detach the event handler, set the IsChecked property, and then reattach it.

myCheckbox.Checked -= myCheckbox_Checked;myCheckbox.IsChecked = true;myCheckbox.Checked += myCheckbox_Checked;


You could use the Click event instead of Checked and use the state of the checkbox like below:

private void normalCheck_Click(object sender, RoutedEventArgs e){    if (normalCheck.IsChecked ?? false) { normal(); }}

Then, this event won't be raised by using normalCheck.IsChecked = true;. It will only be raised by a click.

NOTE: The null-coalescing operator (??) is necessary because IsChecked returns a bool? type which could be null.


If you're referring to changing the checked status without raising the "_Checked" event, you will likely have to override the event handler with a param to tell it to skip the event or not.

Related answer: Change Checkbox value without raising event