Home > Mobile >  How to add wpf component to win app in .NET 6
How to add wpf component to win app in .NET 6

Time:04-16

I create a project Win App with .Net 6.

I wanna add wpf Component to my project but I don't find the ElementHost control in toolbox.

Has this control been removed?

if yes, how to add wpf control to win app?

CodePudding user response:

It looks like .NET 6 Winform designer doesn't support ElementHost.

[my version is Visual Studio 2022 17.1.1] enter image description here

try add ElementHost manually

        private System.Windows.Forms.Integration.ElementHost elementHost;

        private void InitElementHost()
        {
            this.SuspendLayout();
            this.elementHost.Location = new System.Drawing.Point(236, 156); //location
            this.elementHost.Name = "elementHost1";
            this.elementHost.Size = new System.Drawing.Size(200, 100);
            this.elementHost.TabIndex = 0;
            this.elementHost.Text = "elementHost1";
            this.elementHost.Child = null; //wpf control
            this.ResumeLayout(false);
        }

enter image description here

  • Related