Skip to content

[CP to 1.8] Fix focus not restored after Storage Pickers dialog closes#6601

Open
DinahK-2SO wants to merge 5 commits into
release/1.8-stablefrom
user/DinahK-2SO/storagepickers_focus_fix__CP-1-8
Open

[CP to 1.8] Fix focus not restored after Storage Pickers dialog closes#6601
DinahK-2SO wants to merge 5 commits into
release/1.8-stablefrom
user/DinahK-2SO/storagepickers_focus_fix__CP-1-8

Conversation

@DinahK-2SO

Copy link
Copy Markdown
Contributor

This is a cherry-pick of #6544

Summary:
Issue reported in #6505. Storage Pickers leave the WinUI window without keyboard focus after their dialog closes, so the keyboard stops working until the user clicks the window again.

Repro:

  1. in code map a button's Click handler with a picker behavior.
  2. Click the button (dialog opens), pick a file and confirm (dialog closes),
  3. then press Enter.
  4. Before the fix Enter does nothing;
    After the fix Enter re-invokes the button and the dialog reopens.

Fix:
An RAII helper DialogFocusRestorer captures the focused window before the dialog opens and restores focus to it once the dialog closes. Applied to all five pick methods.

**Summary:**
Issue reported in #6505. Storage Pickers leave the WinUI window without keyboard focus after their dialog closes, so the keyboard stops working until the user clicks the window again.

**Repro:**
1. in code map a button's Click handler with a picker behavior.
2. Click the button (dialog opens), pick a file and confirm (dialog closes),
3. then press Enter.
4. Before the fix Enter does nothing;
    After the fix Enter re-invokes the button and the dialog reopens.

**Fix:**
An RAII helper `DialogFocusRestorer` captures the focused window before the dialog opens and restores focus to it once the dialog closes. Applied to all five pick methods.

**Commits:**

* Restore keyboard focus after Storage Pickers dialog closes (#6505)

The COM file dialog runs on a background thread, so SetFocus on close is ignored. Capture the focused window on the UI thread and marshal SetFocus back via the DispatcherQueue. Adds DialogFocusRestorer, applied to all five pick entry points.

* add a manual test case
@DinahK-2SO DinahK-2SO requested a review from a team July 9, 2026 07:25
@DinahK-2SO DinahK-2SO requested review from Scottj1s and agniuks July 9, 2026 07:29
@DinahK-2SO

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@DinahK-2SO DinahK-2SO force-pushed the user/DinahK-2SO/storagepickers_focus_fix__CP-1-8 branch from f62dfde to 49be3cc Compare July 9, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant