I have to second this feature. I know you can bind CloseCommand in AvalonDock, and this is a critical thing in line of business applications:
- Prompting for close in a view model
- Ensuring that the user can close the window (E.G. its not currently performing something)
Essentially any operation that needs to cancel the event so that the window doesn't close.
Sure, we could handle it with the event, but its a pain, especially with asynchronous operations and trying to get it working with prism.
A simple example:
- A user selects to close a window
- The window closing event is fired and handled in the view code-behind
- The code-behind calls a view models ICommand's Execute, which prompts if the user wants to close. Since the prompt is asynchronous, e.Cancel and e.Handled are set to true in the view code-behind
- The user select "yes" they want to close the window, so now we have to set a flag in our view model then call someting to close the window
- The window closing event is fired again and hits the view code-behind, this time it recognizes that the flag on the view model is set, and does not set e.cancel or e.handled and it closes
This example is even more complicated when taking into account prism regions.
I'm trying to get this working by handling it with the events... but when a document is floatig in a floating docksite, and I click the close button on the floating docksite (not the document)... the documents are closed but the floating docksite remains... so now I'm trying to figure out how to determine if there's an open floating docksite with no documents so that I can manually close it.
private void Docksite_WindowsClosing(object sender, ActiproSoftware.Windows.Controls.Docking.DockingWindowsEventArgs e)
foreach(var i in e.Windows.ToList())
if(i.DataContext is DockingItemViewModelBase)
var viewModel = i.DataContext as DockingItemViewModelBase;
// Perform whatever, then if the window should still close, IsClosing is set to true and the window Close()
// function is called
e.Cancel = true;
e.Handled = true;
throw new Exception("Can't handle tab close. Not of type DockingItemViewModelBase");