WPF Check box: Check changed handling
Solution 1:
That you can handle the checked and unchecked events seperately doesn't mean you have to. If you don't want to follow the MVVM pattern you can simply attach the same handler to both events and you have your change signal:
<CheckBox Checked="CheckBoxChanged" Unchecked="CheckBoxChanged"/>
and in Code-behind;
private void CheckBoxChanged(object sender, RoutedEventArgs e)
{
MessageBox.Show("Eureka, it changed!");
}
Please note that WPF strongly encourages the MVVM pattern utilizing INotifyPropertyChanged and/or DependencyProperties for a reason. This is something that works, not something I would like to encourage as good programming habit.
Solution 2:
As a checkbox click = a checkbox change the following will also work:
<CheckBox Click="CheckBox_Click" />
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
// ... do some stuff
}
It has the additional advantage of working when IsThreeState="True"
whereas just handling Checked and Unchecked does not.