Closed jbrue-csiroad closed 3 years ago
Hello jbruening47, thank you for your interest in Win32!
I have automatically added a "needs triage" label to help get things started. Our team will look into the question and answer ASAP. Other community members may also answer the question and provide feedback 🙌
From the docs, it says that
For a walkthrough that demonstrates how to use the wrapped UWP controls, see Host a standard UWP control in a WPF app.
My understanding is that you need to follow these instructions, including the part where you create a UWP project that references the Microsoft.Toolkit.Win32.UI.XamlApplication
NuGet package.
I have exactly the same issue, I cannot add the MapControl to either a VB or C# windows forms / winforms project. I get the message:
Failed to create component 'MapControl'. 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()'
In a response above someone links to instructions. However, the page linked to is titled "Host a standard UWP control in a WPF app using XAML Islands". The problem here is with windows forms, not WPF.
Any indication of when some assistance will be forthcoming?
Thanks!
Hello @marb2000 is there a way to get a status on this issue?
It has been open for over 6 months now. Is there a way to find out if it will be fixed, and if so, when? I have a project that cannot hold any longer, and I will need to investigate non-Microsoft solutions if a fix for this is not forthcoming.
Thanks for any information you can provide!
@bearwarebiz, WinForms designer was completely redo and, unfortunately, there are issues that we don't know when will be fixed. Meanwhile, let me understand a little better your scenario to find a work-around. Is your project a .NET Framework or .NET Core?
Hello @marb2000 , I am trying to do a .NET Framework windows forms application that will display geographic data from .tcx files from fitness apps like FitBit etc.
Unfortunately, XAML Islands no longer support .NET Framework, only .NET Core 3.1. We need to update the docs to make it clear. However, you can still make your scenario work doing these unsupported steps:
Write your code manually insted of using the designer. For example:
private void InitializeComponent()
{
mapControl = new Microsoft.Toolkit.Forms.UI.Controls.MapControl();
this.SuspendLayout();
this.mapControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.mapControl.Name = "mapControl";
this.mapControl.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.mapControl);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
private Microsoft.Toolkit.Forms.UI.Controls.MapControl mapControl;
Here you can find sample that works for me in VS2019 16.8
[Islands_WF_NETFX.zip](https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/files/5484573/Islands_WF_NETFX.zip)
The recommendation is to move your code to .NET Core 3.1 and use WindowsXamlHost instead of the MapControl Windows Forms wrapper.
Hope this helps!
XAML Islands no longer support .NET Framework, so labelling the issue as Won't fix.
@marb2000 what supported method does Microsoft offer to create geographic/mapping data windows forms/desktop applications for Windows?
AFAIN, the most up-to-date control for displaying maps in Windows apps is the UWP one. It's shipped with Windows 10 OS, and you can find it in the namespace Windows.UI.Xaml.Controls.Maps.MapControl. It's a UWP control so the way to use it is using XAML Islands. XAML Islands are only supported with .NET Core 3.1. There is a Windows Forms wrapper for this control that you can find in the Microsoft.Toolkit.Forms.Controls NuGet package. It exposes a very basic functionality of this control.
You can access to the majority of the functionality of the MapControl using another Windows Forms wrapper called WindowXamlHost. And there are two ways:
Just using code behind, no XAML markup at all. This works on simple scenarios: Basically, you should set the Initial type of the UWP content that will be host by this control
windowsXamlHost.InitialTypeName = "Windows.UI.Xaml.Controls.Maps.MapControl";
windowsXamlHost.ChildChanged += WindowsXamlHost_ChildChanged;
You can set the MapControl properties on the ChildChanged event.
Create a user control in a separated UWP project and consume it from the windowXamlHost. So the InitialTypeName will be something like this:
windowsXamlHost.InitialTypeName = "UWPApplication.MyMapControl";
You should follow these guidelines.
Here you can find a project demo that I have created for you: WF_Islands_NETCore_MapControl_Sample.zip
Hi!
Looking at exploring use of the mapControl within our VB WinForm project.
I started with an empty Windows Forms App (.Net Framework) project in VB language (similar tech to our Enterprise package) , and added the Microsoft.Toolkit.Forms.UI.Controls package along with everything else it listed on Accept window
When attempting to drop the MapControl from the Toolbox on a form, I am presented with an error. I assume there is something I am missing but would have also assumed it would add all parts required.
Thoughts?