lundi 7 janvier 2019

How to properly bind Checkbox property

I am working on a wpf application and I am dealing with checkboxes now The problem when I set the Ischecked property to "True" like this:

   <CheckBox  Visibility="{Binding checkVisibility}" IsChecked="true" 
   IsEnabled="True"></CheckBox>

I get my checkbox checked But when I try to bind a booléan property that it's value is "true" i get my checkbox always unchecked I can't see where is the proplem

this is my xaml

 <CheckBox  Visibility="{Binding checkVisibility}" IsChecked="{Binding Path=test,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" IsEnabled="True"></CheckBox>

this is my property

        public bool _test=true;
          public bool test
            {
            get
              {
            return _test;
            }

           set
          {
            if (_test == value)
            {
                return;
            }

            _test = value;
            RaisePropertyChanged("test");
        }
    }

I want my checkbox to reflect my property value and vice versa but it's not the case as my checkbox is always unchecked I am missing something?




Aucun commentaire:

Enregistrer un commentaire