Add-on components that enhance and customize the Visual Studio integrated development environment
Thanks for reaching out.
This is a known limitation when hosting a WPF window inside a Visual Studio extension.
Even when a WPF TextBox has keyboard focus, Visual Studio still pre‑processes certain command keystrokes such as Backspace, Ctrl+A, and Esc and routes them to the previously active document window. These keys never reach WPF’s input pipeline, so handling PreviewKeyDown, KeyDown, or setting e.Handled = true does not work.
This behavior has been reported in Developer Community and related WPF issues and is not caused by focus mismanagement in the WPF window.
Workarounds include:
- Intercepting Win32 messages (e.g., via
HwndSource.AddHook) to block the keys before Visual Studio processes them - Avoiding popup WPF windows for text input and using tool windows or VS-hosted UI instead
At this time, this appears to be a Visual Studio command routing issue rather than a WPF bug.
References
Visual Studio Developer Community report https://developercommunity.visualstudio.com/t/Custom-WPF-Window-ignore-specific-keystr/11037258 [developerc...studio.com]
- Related WPF keyboard routing issue https://github.com/dotnet/wpf/issues/10142 [github.com]
Let us know if the issue persists after following these steps. I’ll be happy to assist further if needed. If the issue has been resolved, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.