WindowsPhone:IsSelected 属性 在集合中没有变化
WindowsPhone: IsSelected property doesn't change in collection
我为 WindowsPhone 8.1 开发 MVVM crud 应用程序
应用程序添加一些数据到列表框。每个项目都有复选框。
如果您选中或取消选中复选框 - 事件处理程序有效,属性 更改值。
但是,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
尝试删除 UpdateSourceTrigger=PropertyChanged,这应该可以解决您的问题
我为 WindowsPhone 8.1 开发 MVVM crud 应用程序
应用程序添加一些数据到列表框。每个项目都有复选框。 如果您选中或取消选中复选框 - 事件处理程序有效,属性 更改值。 但是,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
尝试删除 UpdateSourceTrigger=PropertyChanged,这应该可以解决您的问题