CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.89k stars 1.38k forks source link

IXamlMetadataContainer missing when dragging item from toolbox onto winforms (Framework) from #3376

Open AdmiralSnyder opened 4 years ago

AdmiralSnyder commented 4 years ago

Describe the bug

When trying to drag a control from the Visual Studio toolbox onto a WinForms' form, this error message pops up:

Microsoft Visual Studio

Failed to create component 'WindowsXamlHost'.  The error message follows:

 'System.TypeLoadException: Could not find Windows Runtime type 'Microsoft.Toolkit.Win32.UI.XamlHost.IXamlMetadataContainer'.
   at Microsoft.Toolkit.Forms.UI.XamlHost.WindowsXamlHostBase..cctor()'

Steps to Reproduce

Steps to reproduce the behavior:

  1. I'm following this walkthrough: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/host-standard-control-with-xaml-islands
  2. After creating a WinForms (.net framework 4.7.2) project, and adding a reference to the Microsoft.Toolkit.Forms.UI.Controls 6.1.0 NuGet package. I added the x86 project configuration to the WinForms project.
  3. When I drag a control onto the form (specifically, the InkCavas, but it happens with all the Toolkit controls in the toolbox) and I see the error described before.

Expected behavior

The control should appear, as it did in the WPF (core 3.1) project.

Environment

NuGet Package(s): 
Microsoft.Toolkit.Forms.UI.Controls
Package Version(s): 
6.1.0 

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] October 2019 Update (1909, 18363.900)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)
-- i don't know where to find that

Device form factor:
- [x] Desktop (Surface book 1)
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [ ] 2019 (version: ) 
- [x] 2019 Preview (version: 16.7.0 Preview 3.1)
ghost commented 4 years ago

Hello AdmiralSnyder, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

AdmiralSnyder commented 4 years ago

@Kyaa-dost how would i start fixing this?

Kyaa-dost commented 4 years ago

@AdmiralSnyder If you can fix that and create a PR that would be great 👍

michael-hawker commented 4 years ago

@marb2000 should this scenario work? Do you know what we might be missing here?

AdmiralSnyder commented 4 years ago

@Kyaa-dost i don't know where to start looking to fix that. - the XAML islands project doesn't build, for a start… (well… didn't, a week ago or so...)

Kyaa-dost commented 4 years ago

@AdmiralSnyder Let's see what @marb2000 has to say about this scenario.

marb2000 commented 4 years ago

Using a .NET wrapped control like InkCanvas should work on the .NET Framework, although we encourage everyone to move to .NET Core 3.x . Also you should be able to use the WindowsXamlHost to host others system UWP controls. Custom controls) are not supported. We tested those NET wrapped controls long time ago (2 years?), and they worked well.

Did you try to create the controls via code behind instead of using the designer? Perhaps it's a issue with the WinForms designer.

AdmiralSnyder commented 4 years ago

hey, good idea. i tested it to create an InkCanvas at runtime, and got the problems described here: https://techcommunity.microsoft.com/t5/windows-dev-appconsult/using-xaml-islands-on-windows-10-19h1-fixing-the-quot/ba-p/376330 after solving them by creating a manifest and adding the maxtestedversion thing, it works. not in the designer, though... and core designer bugs out, either... but that's WIP, so... Still, the fact that it's not winforms designer compatible should either be fixed or at least be documented. i'll see whether it is compatible with UserControls this weekend.