This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a base object that has an observable dictionary(of string, object) as a public member. My base object also implement INotifyPropertyChanged and INotifyCollectionChanged. I can load this dictionary up with name value pairs (i.e, dictprops.add("Name", "Mitch") and when I bind it to the itemsource and update it, I can catch the propertychanged events in the window code just fine. However... Say I load up child objects using the same structure, for example, dim person1 as myobj person1.add("name", "Mitch" Personlist.add("Person1", person1) and then bind personlist to the grid...Now I can only see the propertychanged events firing on the person1 object, and cannot catch them on the personlist object that is bound to the grid... methinks I'm not getting something right with the observable collection and the propertychanged events? do I need a routedevent in here somewhere?
|
|
|
The WPF ObservableCollection raises PropertyChanged only for its *own* properties (Item and Count), not for the properties of objects in the collection. By design, the Mindscape ObservableDictionary follows the same behaviour. Therefore you should expect to need to subscribe directly to events on the contained objects rather than getting a "feed" from the collection (and this appears to be the behaviour you are seeing). Does this answer your question? I am not sure if I have understood the issue correctly, so apologies in advance if it doesn't... |
|
|
So how would I do that? I can see that each of the contained objects is raising the event properly, |
|
|
Ok,, this works... I have a handler already on the object itself called dictprops_propertychanged - Then when I'm loading the child objects, I instantiate a handler and assign the delegate accordingly... For ix = 0 To nodeconfig.ChildNodes.Count - 1 Dim nodecomp As XmlNode = nodeconfig.ChildNodes.ItemOf(ix) Dim scompname As String = nodecomp.Attributes("name").InnerTextcomponentObj = New XMLBusinessBase(nodecomp) AddHandler componentObj.PropertyChanged, AddressOf dictProps_PropertyChangedpropDict.Add(scompname, componentObj) NextThis allows my event to be seen by the parent. I need to do this so that my WPF commands know when an object is changed so they can respond accordingly. Are there any cleanup issues that you can see with this approach?
|
|
|
It looks safe to me. The only potential cleanup issue I can see is one obscure case: if you moved an existing componentObj from the one dictionary to another, then you would need to unhook componentObj.PropertyChanged when you removed it from the old dictionary. But I don't imagine that's something you'd be doing so I wouldn't worry about it. |
|