I have a CheckBox in my application that is using the TriState mode. The normal behavior for this mode seems to be cycling between null, false, true.
I’d like to change this behavior so that it cycles between null, true, false.
What’s the best way to do this?
I’ve tried adding a click handler similar to this:
void cb_Click(object sender, RoutedEventArgs e)
{
if (((CheckBox)e.Source).IsChecked.HasValue == false)
{
((CheckBox)e.Source).IsChecked = true;
return;
}
if (((CheckBox)e.Source).IsChecked == true)
{
((CheckBox)e.Source).IsChecked = false;
return;
}
if (((CheckBox)e.Source).IsChecked == false)
{
((CheckBox)e.Source).IsChecked = null;
return;
}
}
But this seems to disable the checkbox entirely. I’m pretty sure I’m missing something that should be obvious.
I guess the event handler and the default behavior are just cancelling each other’s effects, so the checkbox seems disabled…
Actually I recently had to do the same thing. I had to inherit from
CheckBoxand overrideOnToggle: