I'm using MVVM and I need to be able to cancel contentpane close events in a viewmodel class. Originally I thought to use a HeaderTemplate with my own close button, but there are a few scenarios where the stock close button will still show up in a floating window, even if you turn it off with CloseButtonVisibility, and I don't want to re-template any of the DockManager controls. The goal is to handle the closing event for all panes in the viewmodel. Therefore, I'm wondering if I can set up an interaction trigger to invoke a command action for the contentpane's closing event.
Does anyone know how to do this? Any other ideas for a complete MVVM-style contentpane close architecture are also welcome. Thanks.
Or for the sticklers:
EventHandler<PaneClosingEventArgs> closing = null; closing = (s, e) => { if ((item as IViewModel).Close()) container.Closing -= closing; else e.Cancel = true; }; container.Closing += closing;
There are a few areas of basic infrastructure (i.e. closing) that appear to not lend themselves to an MVVM apporach apart from re-templating (a daunting thought given the complexity of this massive control). However, I believe I have a decent enough workaround. I'm using Brian Lagunas' attached behavior, and I added the following line of code to the PrepareContainerForItem method:
container.Closing += (s, e) => e.Cancel = !(item as ViewModel).Close();
which provides an adapter of sorts to map ContentPane.Closing events into the viewmodel plumbing.
Disregard the event trigger idea, as it occurred to me it would have some circular logic. If I went back to my original idea of header templates, I need to be able to put a close button in the floating window header, near where the stock close button is hidden. Further, even another close button appears when two or more panes are docked next to each other in the floating window, and I need to know how to hide that. Has anyone worked this out before for MVVM? Thanks.