dotnet / dotnet/wpf

WPF known issues: the window be activated after dpi changed

Open
#7,561 1 comment 6 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

The inactive window in WPF will be activated after the dpi changed. And I am not sure if this behavior is a bug.

Why?

The HwndTarget will call the SetWindowPos in `OnDpiChanged`, see

https://github.com/dotnet/wpf/blob/c37ab558d3aebf3bfe0038c86e8a4be78d09e03c/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs#L1753-L1770

But seems like it forgot to set the SWP_NOACTIVATE parameter. As the https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos documents says: SWP_NOACTIVATE means does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).

### Reproduction Steps

1. Create an empty wpf project and run the application.
2. Deactive the main window
3. Change the system dpi

### Expected behavior

The main window will not be activated after dpi changed.

### Actual behavior

The main window will be activated after dpi changed.

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

It seems that everyone is used to this behavior

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.