AirspaceMode="Redirect" doesn't respect DPI


On a high DPI monitor running Windows 8.1, the following behavior can be seen in the example DwayneNeed application.

In Clipping mode, the WinForms and WPF controls both render correctly.

If the window contents are set to Redirect, the WinForms and WPF controls are drawn much higher in scale than they should be, which makes them unusable.

file attachments


ravuya wrote Apr 29, 2015 at 7:03 PM

Forgot to add this attachment earlier. This is the window in Clipping mode.

ravuya wrote Apr 29, 2015 at 7:55 PM

It could be related to this issue as my application under development is using per-monitor DPI (and I have two monitors of different DPI settings), but as far as I know the DemoApp does not have the same DPI awareness setting in any configuration or manifest file:


ravuya wrote Apr 29, 2015 at 8:19 PM

For now, I fixed it by changing RedirectedHwndHost.OnRender to use TransformFromDevice when rendering the bitmap's output rectangle instead of using the raw pixel size of the bitmap.
                var bitmapSize = new Vector(_bitmap.Width, _bitmap.Height);
                var dpiScaleToWpfScale = CurrentHwndSource.CompositionTarget.TransformFromDevice;
                var adjustedBitmapSize = dpiScaleToWpfScale.Transform(bitmapSize);

                drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
                drawingContext.DrawImage(_bitmap, new Rect(new Size(adjustedBitmapSize.X, adjustedBitmapSize.Y))); // Changed
This code appears to work properly in my circumstance, but I admit that it is a hack. Any comments on how to fix this "properly" would be super valuable. Thanks, your library rocks.

ravuya wrote Apr 29, 2015 at 8:30 PM

It should also be stated that my solution causes problems with input redirection, so I would not count this as anywhere close to a direct fix.

I also have some odd resizing and other behavior from the underlying WindowsFormsHost.

For what it's worth, my computer (a lenovo W540 laptop) returns a 2.0 scale factor from TransformToDevice, which implies the screen DPI is 192.