事件聚合器和集合
我想使用事件聚合器将我的视图模型与视图同步(视图模型负责模型),这在模型中实现起来非常简单,只需在属性的设置器上调用通知即可。
但当模型有集合时,情况会变得更加复杂。 调用notify的代码应该在哪里? 模型中集合的接口是什么? 列表?
我想到的唯一解决方案是继承一个基类,该基类将使用反射来迭代所有 IList 字段,尝试将它们转换为 INotifyCollectionChanged 并添加一个将调用通知的事件处理程序。
有什么想法吗?
提前致谢, 埃里克.
i want to use an event aggregator to syncronize my viewmodel with the view (the viewmodel ovservs the model), this is very simple to implement in the model, simply call notify on the setters of the properties.
but it gets more complicated when the model has collections.
where should be the code which will call notify?
what would be the interface of the collection in the model?
IList?
the only solution that i've thought of is inhereting form a base class which will use reflection to iterate through all the IList fields, try to cast them to INotifyCollectionChanged and will add an event handler which will call notify.
any ideas?
Thanks in advance,
Erik.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用 ObservableCollection 而不是 IList,因为添加或删除集合时视图不会更新。
I would suggest using ObservableCollection rather than IList as the view will not get updated when the collection is added to or removed from.