microsoft / microsoft/microsoft-ui-xaml

Old window gains focus and moves to foreground when opening new window in `NavigationView.ItemInvoked`

Open
#10,272 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Windowing area-XamlWindow bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### 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

``` xaml








```

```cs
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

https://github.com/user-attachments/assets/dd8cb9f7-f7f5-4773-a589-8aecc7d76cfd

### 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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied sample on Windows 11 with Windows App SDK 1.6.3, comparing windows opened from NavigationView.ItemInvoked and NavigationViewItem.Tapped. Trace the focus and Z-order behavior after Activate(); done when ItemInvoked opens the new window without the old window regaining focus or moving to the foreground.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.