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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…