diff --git a/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs b/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs index b8d6d3e6..72517f3f 100644 --- a/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs +++ b/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs @@ -235,7 +235,14 @@ private void AutoFixSelectedContent() { if (!_autoFixSelectedContent) return; if (SelectedContentIndex >= ChildrenCount) SelectedContentIndex = Children.Count - 1; - if (SelectedContentIndex == -1 && ChildrenCount > 0) SetNextSelectedIndex(); + if (SelectedContentIndex == -1 && ChildrenCount > 0) SetLastActivatedIndex(); + } + + /// Sets the current to the last activated child with IsEnabled == true + private void SetLastActivatedIndex() + { + var lastActivatedDocument = Children.Where(c => c.IsEnabled).OrderByDescending(c => c.LastActivationTimeStamp.GetValueOrDefault()).FirstOrDefault(); + SelectedContentIndex = Children.IndexOf(lastActivatedDocument); } private void OnParentChildrenCollectionChanged(object sender, EventArgs e) => RaisePropertyChanged(nameof(IsDirectlyHostedInFloatingWindow)); diff --git a/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs b/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs index f51452f9..966e820f 100644 --- a/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs +++ b/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs @@ -155,7 +155,7 @@ private void AutoFixSelectedContent() { if (!_autoFixSelectedContent) return; if (SelectedContentIndex >= ChildrenCount) SelectedContentIndex = Children.Count - 1; - if (SelectedContentIndex == -1 && ChildrenCount > 0) SetNextSelectedIndex(); + if (SelectedContentIndex == -1 && ChildrenCount > 0) SetLastActivatedIndex(); } /// @@ -223,6 +223,13 @@ internal void SetNextSelectedIndex() } } + /// Sets the current to the last activated child with IsEnabled == true + private void SetLastActivatedIndex() + { + var lastActivatedDocument = Children.Where(c => c.IsEnabled).OrderByDescending(c => c.LastActivationTimeStamp.GetValueOrDefault()).FirstOrDefault(); + SelectedContentIndex = Children.IndexOf(lastActivatedDocument); + } + /// Updates the property of this object. internal void UpdateIsDirectlyHostedInFloatingWindow() => RaisePropertyChanged(nameof(IsDirectlyHostedInFloatingWindow));