How to remove from DocumentSource on close

May 7, 2012 at 4:14 PM


I can't figure out how to keep collection passed to DocumentSource synchronized with opened documents.

I have ObservableCollection binded to DocumentSource.

How can I remove document from ObservableCollection, when user closes document by clicking the x button?

I would expect DocumentClosed event if there's DocumentClosing.

I can't remove document in  DocumentClosing handler, because the closing could be canceled later.

May 9, 2012 at 10:38 AM
Edited May 9, 2012 at 10:42 AM

Ok I found DockManager.DocumentClose event, thats what I need.

I just recommend to rename it to DocumentClosed to keep some .net naming guidelines.

Also it is defined like
 public event EventHandler DocumentClose
and it leads to ugly code like this:

private void dockManager_DocumentClose_1(object sender, EventArgs e)
var tab = ((AvalonDock.DocumentCloseEventArgs)e).Document;

It should be
 public event EventHandler<DocumentCloseEventArgs> DocumentClose

I would also rename  DocumentCloseEventArgs to DocumentEventArgs to make it more universal so finally
public event EventHandler<DocumentEventArgs> DocumentClosed

May 10, 2012 at 3:11 PM

Naming issues fixed in latest release