gpt4 book ai didi

c# - WindowsPhone : IsSelected property doesn't change in collection

转载 作者:行者123 更新时间:2023-12-03 10:43:43 24 4
gpt4 key购买 nike

我为Windows Phone 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,这应该可以解决您的问题

关于c# - WindowsPhone : IsSelected property doesn't change in collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38778018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com