tags:

views:

28

answers:

1

HI, I'm working in WPF and i have an interesting requirement. I need my checkboxes to be ThreeState, so if only some of the child elements are selected it shows as indeterminate. But when a use clicks it, i want it to select either true or false.

Here is a story to represent my requirements:

item - indeterminate  
    subItem - checked  
    subItem - unchecked  
    subItem - checked  

When a user clicks item, the checkbox should alternate between checked and unchecked. The user should never be able to select 'indeterminate' as a state. Is this possible?

+2  A: 

XAML:

<CheckBox IsThreeState="True" IsChecked="{x:Null}" Click="CheckBox_Clicked" />

Code-behind:

private void CheckBox_Clicked(object sender, RoutedEventArgs e)
  {
     var cb = e.Source as CheckBox;
     if (!cb.IsChecked.HasValue) 
        cb.IsChecked = false;
  }

If you don't like the code-behind solution, then you could sub-class your own control like in the solution for this question.

Bermo
Bingo! thanks mate. Tried it with the Indeterminate event and it didnt work, but clicked does... strange :)
TerrorAustralis