跟踪属性更改中的更改
我想将我的可观察视图模型对象集合过滤为更新的对象。我已经订阅了每个视图模型的属性更改事件。但我不确定如何跟踪对象,因此最终结果将只是在 UI 中更新的对象。
ProgramViewModel Cur=new ProgramViewModel(prg);
Cur.PropertyChanged += new PropertyChangedEventHandler(Cur_PropertyChanged);
program.Add(Cur);
//here program is my observable collection of viewmodels
void Cur_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//What will be the code that will filter out only updated objects
throw new NotImplementedException();
}
//Now in my Save Event handler
private void Save_Click(object sender, RoutedEventArgs e)
{
foreach (ProgramViewModel model in program)
{
//I need only updated objects here to be added to database
}
}
I want to filter my observable collection of viewmodel objects to the objects that are updated. I have subscribed to the Property Changed event for each viewmodel. But I am not sure how shall I track the objects so the end result would be only the objects that are updated in the UI.
ProgramViewModel Cur=new ProgramViewModel(prg);
Cur.PropertyChanged += new PropertyChangedEventHandler(Cur_PropertyChanged);
program.Add(Cur);
//here program is my observable collection of viewmodels
void Cur_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//What will be the code that will filter out only updated objects
throw new NotImplementedException();
}
//Now in my Save Event handler
private void Save_Click(object sender, RoutedEventArgs e)
{
foreach (ProgramViewModel model in program)
{
//I need only updated objects here to be added to database
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是将它们存储在
HashSet
中。这样,您就不必担心跟踪集合中已有的内容:I would just store them in a
HashSet<ProgramViewModel>
. That way, you won't have to worry about tracking which ones are already in the collection: