-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
This issue has been moved from a ticket on Developer Community.
[severity:It’s more difficult to complete my work]
[severity:it's a BUG]
My WPF needs to handle Multimonitor DPI inside VSTO Office addin.
Since my WPF is hosted, I can’t control the manifest of the host app and access is denied when I try to set the ProcessDpiAwareness in code.
So what I need to do:
set the Process/Thread DPIAwarenessContext.
set a HwndSourceHook, catch the WM_DPICHANGED and forward dpi and size to WPF.
set SetRootDPI on my Window.
set LayoutTransform to Window
set LayoutTransform To Window’s child.
It’s cumbersome but it works, EXCEPT for Popups and Tooltips that end up in the wrong location (or monitor) and in the wrong scale.
What happens:
In hosted WPF the HwndSource is ‘stuck’ to SystemDPI. The layout transforms have to bridge the delta between actual dpi and system dpi. But Popups and Tooltips don’t fall within the Window’s visual tree and require workrounds. For generic Tooltips I can bind to the ancestor Window’s LayoutTransform. But some will be defined in resources used for a DataGrid and cannot locate the ancestor Window.
Also Window location/sizes (including Min/Max Height/Width) are in SystemDPI and require manipulation. Not hard, but contrary to WPF design philosophy.
From a layman’s perspective you’d think all this is needlessly difficult.
There should be no need for hooking, setrootdpi, layouttransforms and the Popup problems/workarounds.
The solution?
When I set the DpiContextAwareness the HwndSource SHOULD handle DpiChanges itself. Afaik for HwndSource the (windows 8.1) ProcessAwareness is dominant, and in a hosted environment the (win10) AwarenessContext is ignored. If HwndSource knows the correct DPI then PopupRoot will know as well.
Microsoft please fix this!
I have a demo project. It’s currently VB, but easily changed to C#. And it also has a good workaround for the Modeless WPF input focus issue. Another WPF bug/design feature that never gets addressed.
Kind regards,
Jurgen (aka keepITcool)
Original Comments
Feedback Bot on 7/17/2024, 07:30 AM:
(private comment, text removed)
Original Solutions
(no solutions)