This project is read-only.

Close all but this

Oct 17, 2010 at 5:09 PM

Hi

I am searching for a way that when the User executes the Command "Close all but this", I can determine, which Documents are be closed and which Document still be open.

Thans for your help!

Best Regards, Thomas

Jan 12, 2012 at 10:21 PM

Were you ever able to handle the Close All But This command? I have a similar need.

 

Shane

Mar 28, 2012 at 2:34 PM

Hello,

download the sample http://www.codeproject.com/Articles/239342/AvalonDock-and-MVVM and look how it is implemented here. You need to attach to document content "Closing" event in DockManager (be careful, this event is also on DockingManager, do not attach to this). In that sample it is this line 

documentContent.Closing += new EventHandler<CancelEventArgs>(documentContent_Closing); (AvalonDockMVVMSampleCode\AvalonDockMVVMSampleCode\AvalonDockMVVM\AvalonDockHost.xaml.cs file)

In the event handler, argument "objec sender" is the document that needs to be closed. So if user has 3 open documents and clicks "Close all but this", this event handler will be invoked twice, each time for particular document that needs to be closed. Avalon handles this automatically, so you do need to check which document content needs to be closed or stay open. Just cast the sender to your content, get the document from the content and close it. In my solution this works well. And Close or Close All But This works as you would expect.

 

private void documentContent_Closing(object sender, CancelEventArgs e)       

{           

var documentContent = (DocumentContent)sender;           

var document = documentContent.DataContext;

document.Close();

}