samedi 7 février 2015

WPF Bind checkbox to bool?

I have a WPF checkbox binded to ViewModel nullable boolean property. I am setting this property to false or true in Constructor, to avoid Interminent state but no matter what I do the Initial state of checkbox stays grayed. The binding working just fine since once I change the state by clicking the checkbox on UI I am getting controls values (true/false). Any Ideas?


XAML



<CheckBox Margin="0,4,0,3" VerticalAlignment="Center" Content="Mutual"
IsChecked="{Binding MutualChb}" />


ViewModel



public ContstrutorViewModel()
{
MutualChb = true;
}


private bool? _mutualChb;
public bool? MutualChb
{
get { return _mutualChb; }
set {
_mutualChb = value;
_mutualChb = (_mutualChb != null ) ? value : false;
OnPropertyChanged("MutualChb"); }
}




Aucun commentaire:

Enregistrer un commentaire