I’m using ObservableCollections as the ItemsSource for some of my bindings, and have run into a scenario where I would like to call OnCollectionChanged manually to notify that the list should be re-checked by the binding engine. (The BindingList analogue is OnListChanged).
Here’s where the trouble begins. Maddeningly, these methods are protected and can’t be called without subclassing these types. Ironpython supports this, but when I attempt to subclass, it fails spectacularly – even when I don’t specify any overriding methods:
>>> class ObservableCollectionEx(System.Collections.ObjectModel.ObservableCollection):
... pass
...
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: Object reference not set to an instance of an object.
>>> class BindingListEx(System.ComponentModel.BindingList):
... pass
...
Traceback (most recent call last):
File "<string>", line 1, in <module>
SystemError: Object reference not set to an instance of an object.
I’m about to give up, and all I wanted to do was make one friggin’ call to OnCollectionChanged! Help!
After doing some more research I’ve found a workaround. Reading this article on inheriting from generic classes sheds some light on what is going on behind the scenes, most notably this explanation:
According to this, what I’m trying to do in my original post (inheriting from
ObservableCollectionsandBindingLists) is of the second form; trying to keep both the base and sub-class parameterized. While I still think this has to be possible in some way in IronPython, I can’t figure out the syntax to do it, so I’ll settle for the first form for now. And whaddaya know, it works:So in this example,
BindingListExis non-generic, and subclasses from theBindingListparameterized base class that has been fedstras its parameter. This works for now. If anyone figures out how to do Open Construct generic inheritance (that second form up there), feel free to post it here and you’ll get the accepted answer, as that was my original goal. For now, this will have to do.