Per monitor DPI Awareness causes issues with touch and pen input
On a Surface Pro 2 when I use [assembly: DisableDpiAwareness] it causes an issue where touch and stylus input has a large offset to the bottom right. This causes trouble when trying to manipulate onscreen controls such as a button click without a mouse (which works fine).
I managed to resolve this issue:
The problem arose for me when creating the startup window from a custom Startup method in App.xaml.cs. instead of using StartupUri in App.xaml. This caused the startup window (but not any windows created from this window) to interpret touch coordinates wrong.
The problem seems to be that ModernUIHelper.TrySetPerMonitorDpiAware is called to "late" during application startup (called in the DpiAwareWindow constructor). Manually calling it during OnStartup in App.xaml.cs does not help either.
Looking at the documentation for SetProcessDpiAwareness (the winapi function called by the helper) the following is found:
You must call this API before you call any APIs that depend on the dpi awareness.
My guess is that this constraint is violated when calling the function from OnStartup or a custom startup.
The fix is simple: The first thing the auto-generated wpf main function does is to create the App object, so creating a constructor and calling the helper function make everything work:
public partial class App : Application
{
public App()
{
ModernUIHelper.TrySetPerMonitorDpiAware();
}
}
I'd be happy to provide a PR for this issue, but I don't know how to fit it in the scope of this library.