R – WPF treeview – How do i know when a treeviewitem was added to the treeview

wpf-controls

I have a treeview which is bound to an observablecollection via HierarchicalDataTemplate. I cant seem to find any treeview functionality that provides me notifications that at any level a new treeviewitem was added.

I know that i can bubble item addition notification to my model's root and raise property changes which can be handled, but I'm trying to find a way doing so by my view without adding this functionality to the model/view-model.

Thanks, Oren.

Best Answer

You are already using an Observable Collection, which notifies when the collection is changed - so hook into this event rather than into the treeview, which is also an observer of the same collection.

Related Topic