How to add XamlHost to WPF project?

233 views Asked by At

Based on this issue, I migrated my WPF project (which was targeting .NET Framework) to target .NET Core 3.1. Theoretically this step would allow to use Microsoft.Toolkit.Wpf.UI.XamlHost in order to host Windows 10 controls in my WPF app.

I created a new WPF project, which targets .NET Core, and moved the source code to this new project and solved every dependency issue.

As I installed the Microsoft.Toolkit.Wpf.UI.XamlHost library (6.1.2) via Nuget Package Manager (just the following line was added to the .csproj file: <PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.1.2" />), the project could compile but couldn't run. It displayed the following error message:

configuration error message

When I removed the library dependency, the project started again...

I think the problem is not with the manifest file, because it has not changed. Then what could be the problem? Where to start to search it? Maybe with one of the other dependencies? Where can I find that application event log? (I was searching a lot, but not found).

I tried the sample app and it works fine, so maybe is it possible that something interferes with the XamlHost in my project?

1

There are 1 answers

0
Attila Szász On BEST ANSWER

Finally I could add the XamlHost. The conflict was with the Dpi awareness settings in the manifest file. Removed the following lines:

<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>

Based on this issue, the dpi awareness should be set to PerMonitorV2 in order to be able to submit the application to the store. Now I had to remove because it was in conflict with the XamlHost.

I'm wondering if I can release the app with this modification...