Old window gains focus and moves to foreground when opening new window in `NavigationView.ItemInvoked`
Scighost opened this issue · 0 comments
Scighost commented
Describe the bug
When handling the NavigationView.ItemInvoked
event to open a new window, the old window unexpectedly regains focus and moves to the foreground after the new window is shown. This disrupts the user experience as the old window should remain in its current state and not interfere with the new window. However, this issue does not occur when opening a new window inside the NavigationViewItem.Tapped
event.
Steps to reproduce the bug
<Window x:Class="App.MainWindow">
<NavigationView ItemInvoked="NavigationView_ItemInvoked">
<NavigationView.PaneHeader>
<NavigationViewItem Content="Tapped"
Icon="Accept"
Tapped="NavigationViewItem_Tapped" />
</NavigationView.PaneHeader>
<NavigationView.MenuItems>
<NavigationViewItem Content="ItemInvoked" Icon="Cancel" />
</NavigationView.MenuItems>
</NavigationView>
</Window>
private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
new MainWindow().Activate();
}
private void NavigationViewItem_Tapped(object sender, TappedRoutedEventArgs e)
{
new MainWindow().Activate();
}
Expected behavior
The new window should open and gain focus without affecting the old window's focus or Z-order.
Screenshots
bug.mp4
NuGet package version
WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003
Windows version
Windows 11 (23H2): Build 22631
Additional context
No response