Hi,
I'm trying to find a way to know when a new pane is added so that I can "do something" when that happens (for example, set a binding between the new pane's header and a property in its content.) I've tried to subclass the XamDockManager and add a event handler to the Panes property's CollectionChanged event, but that seems to be called only once, and there's nothing in the NotifyCollectionChangedEventArgs. I'm using MVVM/Prism/MEF with the XamDockManagerRegionAdapter, so I also need to avoid the need for UI-specific stuff in my client code.
Is this at all possible?
Thanks,Michel
I was afraid you were going to say that. :) I've thought about modifying NCAL or the ContentPaneProxy I found on a blog here (can't remember if it was yours though), but that's a bit too much of a time investment for now. This will probably be a "home project."
As a workaround for now, I ended up writing an attached behavior for the dock manager. The content pane's view model implements an interface that ensures that "Id" and 'HeaderName" properties are available. The the Id is assigned to the property bound to the attached behavior (which triggers the behavior), and the attached behavior simply goes through all the panes, examining their content's datacontext to match the Id. When the match is found, if there is no binding on the Header property of the pane, it sets it to the HeaderName property in the datacontext. It's not the most elegant solution, but it's minimal, non-UI code in the datacontext and can easily be taken once I implement a better solution.
No there is no event in XamDockManager when panes are added/removed from somewhere within the control. Since the xamDockManager isn't adding/creating panes by itself, you must have code that is creating the panes (e.g. using the NCAL source or perhaps using the sample code I had in a blog about binding to a collection) so you would likely need to modify whatever source that is based on your needs.