为什么 ObservableCollection 隐藏 INotifyPropertyChanged.PropertyChanged
我有一个派生自 ObservableCollection 的类。 我想向此类添加一些属性(不是集合中的项目),但发现它的 PropertyChanged 实现受到保护。 由于它受到保护,我认为这就是我在 XAML 中绑定到这些新属性的尝试失败的原因。
如果没有创建一个挂起此类实现 INotifyPropertyChanged 并容纳这些新属性的对象,有没有办法解决我忽略的问题?
I have a class that derives from ObservableCollection. I wanted to add some properties to this class (not the items in the collection) but have discovered that its implementation of PropertyChanged is protected. Since its protected I assume that is why my attempts at binding to these new properties in XAML are failing.
Short of creating an object that hangs off this class that implements INotifyPropertyChanged and houses these new properties, is there a way around this that I'm overlooking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果类实际上实现了接口,但显式地实现了这一点,并将访问修饰符放在具体实现上,那么您所需要做的就是在接口本身的上下文中获取该对象,然后就可以使用它了。 例如......
这可能会失败,因为它的
PropertyChanged
实现受到保护。 但是,您可以这样做:这应该可行,因为您将对象作为接口的实例来处理,而不仅仅是通过类定义访问接口成员。
我没有做过任何 WPF,所以我不知道
ObservableCollection
是否实际实现了INotifyPropertyChanged
,但如果它实现了,那么这应该可以工作。If the class actually implements the interface but does so explicitly and places access modifiers on the concrete implementation, all you need to do is get that object in the context of the interface itself and you can use it. For example..
That might fail, since its implementation of
PropertyChanged
is protected. You could, however, do this:This should work, as you're dealing with the object as an instance of the interface, rather than just accessing interface members through the class definition.
I haven't done any WPF, so I have no idea if
ObservableCollection
actually implementsINotifyPropertyChanged
, but if it does then this should work.ObservableCollection 确实实现了 INotifyPropertyChanged,http://msdn.microsoft.com/en-us /library/bb460458.aspx,但是...
我似乎太早发布了这个问题,我的测试应用程序来挑战我的假设是有效的。
ObservableCollection does implement INotifyPropertyChanged, http://msdn.microsoft.com/en-us/library/bb460458.aspx, however...
I posted this question too soon it seems, my test app to challenge my assumptions works.