xain
xain

Reputation: 13839

Modification required to transform a checkbox to a three-state one in WPF

I have a checkbox defined as follows:

<CheckBox x:Name="T09_CH105" IsChecked="{Binding Path=T09_CH105,Mode=TwoWay}" Content="Others"/>

And its corresponding DataMember:

[DataMember]
public Boolean T09_CH105 {
  get { return _T09_CH105; }
        set { if (_T09_CH105 != value) {
            _T09_CH105 = value;
            OnPropertyChanged("T09_CH105");
          }
      }
  }

How can I make it a three-state checkbox ? I haven't been able to figure out how to adapt what I've read online to my code.

Thanks

Upvotes: 1

Views: 462

Answers (2)

Davide Piras
Davide Piras

Reputation: 44605

you should add the attribute:

IsThreeState="True"

to your XAML

Upvotes: 3

Zebi
Zebi

Reputation: 8882

Use a nullable bool: bool? or Nullable<bool> (see the corresponding msdn article for reference)

If the status is null the wpf checkbox displays a "half checked" state.

Upvotes: 1

Related Questions