Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set checkbox.isChecked without raising event

Tags:

c#

checkbox

wpf

Is there a way of checking the CheckBox without running the code associated to checking it? Just for visual appearance.

Edit:

private void normalCheck_Checked(object sender, RoutedEventArgs e)
{
    normal();
}

Imagine that I want to set the normalCheckBox.IsChecked=true; but without raising the event. Is that possible?


1 Answers

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;
like image 182
keyboardP Avatar answered Sep 09 '25 00:09

keyboardP