diff --git a/source/Components/AvalonDock/Controls/NavigatorWindow.cs b/source/Components/AvalonDock/Controls/NavigatorWindow.cs index ccfa3562..7deee8ca 100644 --- a/source/Components/AvalonDock/Controls/NavigatorWindow.cs +++ b/source/Components/AvalonDock/Controls/NavigatorWindow.cs @@ -98,6 +98,7 @@ internal NavigatorWindow(DockingManager manager) DataContext = this; Loaded += OnLoaded; Unloaded += OnUnloaded; + Deactivated += OnDeactivated; UpdateThemeResources(); } @@ -380,11 +381,7 @@ protected override void OnKeyUp(KeyEventArgs e) { if (!(e.Key == Key.Tab || e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)) { - Close(); - if (SelectedDocument != null && SelectedDocument.ActivateCommand.CanExecute(null)) - SelectedDocument.ActivateCommand.Execute(null); - if (SelectedDocument == null && SelectedAnchorable != null && SelectedAnchorable.ActivateCommand.CanExecute(null)) - SelectedAnchorable.ActivateCommand.Execute(null); + CloseAndActiveSelected(); e.Handled = true; } base.OnKeyUp(e); @@ -520,6 +517,21 @@ private void OnLoaded(object sender, RoutedEventArgs e) private void OnUnloaded(object sender, RoutedEventArgs e) => Unloaded -= OnUnloaded; + private void OnDeactivated(object sender, EventArgs e) + { + CloseAndActiveSelected(); + } + + private void CloseAndActiveSelected() + { + Deactivated -= OnDeactivated; + Close(); + if (SelectedDocument != null && SelectedDocument.ActivateCommand.CanExecute(null)) + SelectedDocument.ActivateCommand.Execute(null); + if (SelectedDocument == null && SelectedAnchorable != null && SelectedAnchorable.ActivateCommand.CanExecute(null)) + SelectedAnchorable.ActivateCommand.Execute(null); + } + private void FocusSelectedItem(ListBox list) { if (list.SelectedIndex >= 0)