XamlHost:NavigationView and drag and drop don't work correctly if display scaling isn't 100%

Chuck Bohling 346 Reputation points
2020-08-12T23:40:23.543+00:00

As far as I can tell, this is a bug in XamlHost. If display scaling is 100%, everything's ok. But if scaling is not 100%, drag and drop don't work correctly.

I have a WPF app that's using a Xaml Island to host a UWP NavigationView. The MainWindow.xaml looks like:

<Window x:Class="WpfApp1.MainWindow"
...
<xamlHost:WindowsXamlHost x:Name="NavigationView" Loaded="NavigationView_Loaded"
InitialTypeName="Windows.UI.Xaml.Controls.NavigationView"/>
...

Each of the NavigationViewItem's have drag and drop programmatically enabled. If scaling is 100%, the correct handlers are called. But if not 100%, the X and Y positions are incorrect and the wrong handlers get called. I was able to hack my code and see that the positions sent to the handlers are not the same as the MainWindow coords. They should be. If I multiplied the handler's position by the scaling fraction, they match the MainWindow coords. Apparently, XamlHost is using the wrong coordinate system in this case.

If I'm correct about this, it basically means that Xaml Island/NavigationView and drag and drop cannot be used.

Anyone else seen this problem? Any comment from Microsoft?

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,681 questions
{count} votes

Accepted answer
  1. Chuck Bohling 346 Reputation points
    2020-11-26T20:07:27.413+00:00

    I filed an issue directly with the dev team at github. Here's the issue 283. It's a bug in XamlHost and will not be fixed. If I understand it correctly, drag and drop will not work correctly with any UIElement if the display scale is not 100%. I had to abandon Xaml Islands and go back to WPF.

    0 comments No comments

0 additional answers

Sort by: Most helpful