Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs =================================================================== diff -u -rf8f60a1f81812c31026cdb2bcda40e70cfc3d434 -re453a75b0515e243e126c0b71474ee387db64d2b --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision f8f60a1f81812c31026cdb2bcda40e70cfc3d434) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision e453a75b0515e243e126c0b71474ee387db64d2b) @@ -131,6 +131,7 @@ SetFocusToView(view); + layoutDocument.Closing += OnLayoutDocumentClosing; layoutDocument.Closed += OnLayoutDocumentClosed; } @@ -293,10 +294,25 @@ } } + private void OnLayoutDocumentClosing(object sender, CancelEventArgs e) + { + var layoutDocument = (LayoutDocument) sender; + var view = GetView(layoutDocument.Content); + + if (ActiveDocumentView == view) + { + // Note: When removing the active document view via AvalonDock, always set focus to this + // view in order to make the view host behave as expected (in this case AvalonDock will help + // us selecting the previous active document view based on active content changes). + SetFocusToView(view); + } + } + private void OnLayoutDocumentClosed(object sender, EventArgs e) { var layoutDocument = (LayoutDocument) sender; + layoutDocument.Closing -= OnLayoutDocumentClosing; layoutDocument.Closed -= OnLayoutDocumentClosed; OnViewClosed(GetView(layoutDocument.Content));