Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Controls/src/Core/Shell/ShellElementCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public void Clear()
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, list));
}

protected void RestoreDeclarationOrder(BaseShellItem item)
{
if (!Inner.Contains(item))
{
return;
}

PauseCollectionChanged();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Logic and Correctness Verification - The original two-content reproduction still leaves the displayed flyout in the wrong order. Set CurrentItem to the second ShellContent before adding the first and then the second content, as in the new test: adding the first content caches the flyout as [second, first]. Pausing the visible notifications means both replayed notifications observe the final [first, second] collection. ShellFlyoutItemsManager.UpdateFlyoutGroupings compares group sizes, but its element-comparison loop uses j > topLevelNew.Count, so it never detects this same-size reorder and never synchronizes FlyoutItems. Shell.Items is corrected while the displayed flyout remains [second, first]. Correct the flyout reorder detection alongside this batching and extend the regression test to assert the actual flyout order through shell.GenerateTestFlyoutItems(), not only Shell.Items and selection.


try
{
Inner.Remove(item);
Inner.Add(item);
}
finally
{
ResumeCollectionChanged();
}
}
public virtual void Add(BaseShellItem item) => Inner.Add(item);

public virtual bool Contains(BaseShellItem item) => Inner.Contains(item);
Expand Down
10 changes: 9 additions & 1 deletion src/Controls/src/Core/Shell/ShellItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ item is TabBar
}
}

Inner.Add(item);
// Restore declaration order when CurrentItem is set during XAML loading.
if (Routing.IsImplicit(item) && Inner.Contains(item))
{
RestoreDeclarationOrder(item);
}
else
{
Inner.Add(item);
}
}
}
}
16 changes: 16 additions & 0 deletions src/Controls/tests/Core.UnitTests/ShellFlyoutItemGroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ public void FlyoutItemsGroupTestMoveGroup()
Assert.Equal(shell.Items[0], flyoutItems[0][0]);
}

[Fact]
public void CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents()
{
var shell = new TestShell();
var firstContent = CreateShellContent();
var currentContent = CreateShellContent();

shell.CurrentItem = currentContent;
shell.Items.Add(firstContent);
shell.Items.Add(currentContent);

Assert.Equal(firstContent, shell.Items[0].CurrentItem.CurrentItem);
Assert.Equal(currentContent, shell.Items[1].CurrentItem.CurrentItem);
Assert.Equal(currentContent, shell.CurrentItem.CurrentItem.CurrentItem);
}

MenuItem CreateNonVisibleMenuItem()
{
MenuItem item = new MenuItem();
Expand Down
Loading