Missing LostKeyboardFocus event in Windows 11

Heiko 1,211 Reputation points
2022-02-22T16:33:28.253+00:00

When the MainWindow's LostKeyboardFocus event is triggered in my WPF (bridge) app, i.e. when the user clicks the mouse outside my app, the MainWindow will be hidden with Hide() in the LostKeyboardFocus handler. If the user clicks the app icon in the taskbar another time, the new app instance sends a message to the already existing MainWindow, whereupon it shows itself again with Show(). The new app instance will then be closed.

Unfortunately, under Windows 11, when the MainWindow is displayed again, the LostKeyboardFocus event is no longer triggered if the user clicks outside the MainWindow. However, under Windows 8.1 and under Windows 10, the LostKeyboardFocus event is triggered. Under Windows 11, only when the user clicks inside the app and then outside the app, the LostKeyboardFocus event is triggered and the MainWindow can be hidden again.

The problem occurs when I launch the app with VS 2022 under Windows 11. The problem also occurs when I create the app package under Windows 10 with VS 2017 and then sideload it under Windows 11. It works under Windows 10, but not under Windows 11.

The app is made visible as follows:

Show();
Activate();

The app has no title bar, and it is essential for the usage of the app that its window hides itself when clicked outside the app.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,291 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,244 questions
{count} votes