views:

1242

answers:

3

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?

+2  A: 

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..

ObservableCollection collection;

collection.PropertyChanged += ...;

That might fail, since its implementation of PropertyChanged is protected. You could, however, do this:

ObservableCollection collection;

INotifyPropertyChanged iproperty = collection;

iproperty.PropertyChanged += ...;

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 implements INotifyPropertyChanged, but if it does then this should work.

Adam Robinson
+1  A: 

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.

scauer
I tested my answer and discovered I was wrong, sorry for misleading you, or at least inadvertently attempting to.
+1  A: 

Sure enough, bug in my code. sigh...Thanks for everyone's responses and sorry to waste your time.

scauer
Would be nice if you would accept an answer, as others may have similar questions.
Adam Robinson