jeudi 4 août 2016

WindowsPhone: IsSelected property doesn't change in collection

I develop MVVM crud app for WindowsPhone 8.1

App add some data to ListBox. Every item has checkbox. If you check or uncheck checkbox - event handler works, property change value. But, the value of IsSelected property doesn't change in stored collection.

View.xaml - checkbox code

  <CheckBox  x:Name="checkbox" IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<CheckBox.DataContext>
<loal:DataStorageModel/>
 </CheckBox.DataContext>
  </CheckBox> 

DataStorageModel.cs

  public class DataStorageModel : INotifyPropertyChanged
    {
        public string Name { get; set; }
        public string Surname { get; set; }
        public int Age { get; set; }
        private bool _isSelected;
        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                if (_isSelected != value)
                {
                    _isSelected = value;
                    OnPropertyChanged("IsSelected");
                }
            }
        }
            public event PropertyChangedEventHandler PropertyChanged;
            protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

All code on GitHub - http://ift.tt/2ayNzrx




Aucun commentaire:

Enregistrer un commentaire