我为WindowsPhone 8.1开发MVVM crud app
App向ListBox添加一些数据。每个项目都有复选框。 如果选中或取消选中复选框 - 事件处理程序有效,属性更改值。 但是,IsSelected属性的值在存储集合中不会更改。
View.xaml - 复选框代码
<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));
}
}
}
GitHub上的所有代码 - https://github.com/OlegZarevych/CRUD_WP81
答案 0 :(得分:0)
尝试删除应该解决问题的UpdateSourceTrigger = PropertyChanged