CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
383 stars 89 forks source link

WindowsXamlHost control for Windows Forms Example Not Working #262

Closed SPWiggins closed 4 years ago

SPWiggins commented 4 years ago

Hi

I am trying to run through the very basic example on the page below, following the instructions for WinForms

https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/windowsxamlhost

I keep getting errors when trying to drag a WindowsXamlHost control onto the designer

I have been communicating on MSDN forums and this process describes to problem and what I have tried, please see the following link Problem with WinForms https://social.msdn.microsoft.com/Forums/en-US/993f21f0-2d8a-43ec-9bdc-c42ab4187314/xaml-islands?forum=winforms

Can anyone help please with my problem. I really need to try and get some modern UWP controls into my WinForms program.

I did post on Stack Exchange as advised. Please see following link https://stackoverflow.com/questions/61520707/windows-toolkit-xamlhostcontrol-in-winforms

ghost commented 4 years ago

Hello Applied-Acoustic-Engineering, 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 🙌

Kyaa-dost commented 4 years ago

@marb2000 any insight on this?

marb2000 commented 4 years ago

The doc is no up-to-date and we are going to update it soon.

Also, there is an issue with the Windows Forms designer in Visual Studio 2019 16.6+ that needs to be debugged:

image

Meanwhile, for using WindowXamlHost in WinForms you can do something like:

public Form1()
        {
            InitializeComponent();

            this.windowsXamlHost1 = new Microsoft.Toolkit.Forms.UI.XamlHost.WindowsXamlHost();
            this.windowsXamlHost1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
            this.windowsXamlHost1.InitialTypeName = "Windows.UI.Xaml.Controls.ColorPicker";
            this.windowsXamlHost1.Location = new System.Drawing.Point(0, 0);
            this.windowsXamlHost1.Name = "windowsXamlHost1";
            this.windowsXamlHost1.Size = new System.Drawing.Size(800, 800);
            this.windowsXamlHost1.TabIndex = 0;
            this.windowsXamlHost1.Text = "windowsXamlHost1";
            this.windowsXamlHost1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Controls.Add(this.windowsXamlHost1);
        }
        private Microsoft.Toolkit.Forms.UI.XamlHost.WindowsXamlHost windowsXamlHost1;

The application will require to set the maxversiontested Id="10.0.18358.0" in the app manifest:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
        <maxversiontested Id="10.0.18358.0"/>
    </application>
  </compatibility>

Hope this helps.

Happy XAML coding!