c# - 如何在.NET 6中添加wpf组件到win应用程序

标签 c# wpf winforms .net-core .net-6.0

我使用 .Net 6 创建了一个项目 Win App

我想将 wpf 组件添加到我的项目中,但我在 toolbox 中找不到 ElementHost 控件。

此控件是否已删除?

如果是,如何将wpf控件添加到win应用程序?

最佳答案

.NET 6 Winform 设计器似乎不支持 ElementHost。

[我的版本是 Visual Studio 2022 17.1.1] enter image description here

尝试手动添加 ElementHost

        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

关于c# - 如何在.NET 6中添加wpf组件到win应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71880529/

相关文章:

c# - 我现在应该为此目的使用抽象基类吗?

c# - 用C#生成完全随机的偶数

wpf - WPF 不支持 10 位显示器(又名 30 位颜色)吗?

c# - WPF 游戏编辑器 - 在 UI/代码中更新属性

c# - C# 中的右对齐组合框

c# - 如何在 Convert.TryFromBase64String() 中使用 Span?

c# - 使用生成配置在 Visual Studio 中创建项目的多个版本

.net - 当涉及 (WPF) native 图像时,如何获得混合模式小型转储的完整堆栈跟踪?

c# - 使用 Windows 窗体实现接口(interface)

vb.net - 如何从 ShowDialog 窗口返回一个值?