带 INotifyPropertyChanged 的 SortedSet
我有这样的事情:
public class CPerson: INotifyPropertyChanged
public class CPeople: SortedSet<CPerson>
public class CMain
{
private CPeople _people;
}
我想知道在 CMain
中,CPeople
中是否发生了某些更改,添加或删除了新人员,或者某些 CPerson< 中发生了某些更改/code> 在
CPeople
中,我已经在 CPerson
上实现了 INotifyPropertyChanged
但我不知道在 CPeople 上实现了什么接口
类以及如何通过 CPeople
向 CMain
发出 PropertyChanged
事件。
谁能帮助我吗? 问候。
I have something like this:
public class CPerson: INotifyPropertyChanged
public class CPeople: SortedSet<CPerson>
public class CMain
{
private CPeople _people;
}
I want to know in CMain
if something was changed in CPeople
, new person was added or deleted or something was changed in some CPerson
in CPeople
, i have implemented INotifyPropertyChanged
on CPerson
but i don't have any brilliant idea what interface implement on CPeople
class and how in good way get out PropertyChanged
event over CPeople
to CMain
.
Can anyone help me?
Greetings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用
ObservableCollection
。如果您确实需要 SortedSet,您还可以自己实现 INotifyCollectionChanged 和 INotifyPropertyChanged 接口。您可以继续前进的一种方法是创建围绕 SortedSet 的集合类,如下所示:
I would use
ObservableCollection<Person>
. If you really need a SortedSet, you can also implement the INotifyCollectionChanged and INotifyPropertyChanged interfaces yourself.One way you could go forward could be to create your collection class wrapped around SortedSet, like so:
如果您必须使用 SortedSet<>也许您可以创建一个实现 INotifyCollectionChanged 的后代类(来自 SortedSet<>)。或者,如果您不依赖于 SortedSet<>使用 ObservableCollection<>反而。
If you have to use SortedSet<> maybe you could create a descendant class (from SortedSet<>) that implements INotifyCollectionChanged. Or if you are not tied to SortedSet<> use ObservableCollection<> instead.
创建您自己的界面,
IPeopleChanged
等,其中包含诸如PersonAdded(Person p)
、PersonRemoved(Person p)
等事件以及诸如PersonPropertyChanged(Person p,PropertyChangedEventArgs arg)
,使用集合中的 add 方法为集合订阅添加到集合中的项目的属性更改事件,并将这些事件一起冒泡,然后订阅集合中的事件在 CMain.总而言之,您的集合现在有 3 个事件。一个在添加项目时触发,一个在删除项目时触发,一个在项目更改时沿着链传递 PropertyChanged 事件。
Create your own interface,
IPeopleChanged
etc, with events likePersonAdded(Person p)
,PersonRemoved(Person p)
,and something likePersonPropertyChanged(Person p,PropertyChangedEventArgs arg)
, use the add method in your collection to subscribe your collection to the property change events from your items added to the collection, and bubble these along, and subscribe to the events in your collection in CMain.So to sum up, your collection now has 3 events.one which fires when an item added,one when an item removed, and one that passes the PropertyChanged event along the chain when an item has changed.