如何获取窗体中的控件



我有一个Controls.ItemsControl(实际上是HelixViewport3D),想把它添加到一个Forms.UserControl中。

我已经试过this.Controls.Add(new HelixViewport3D());这是UserControl的衍生物但是,这导致了错误HelixToolkit.Wpf.HelixViewport3D' to 'System.Windows.Forms.Control。这是有道理的,因为它们不会从彼此那里继承任何东西。在这些情况下是否有一种包装类?

using HelixToolkit.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

    public partial class HelixForm : Form
    {
        public HelixForm()
        {
            InitializeComponent();
            var _3Dcntr = new HelixViewport3D();
            this.Controls.Add(_3Dcntr);//doesn't work
            //what we worked out so far
            var elemHost = new ElementHost();

        }
    }

我还注意到,应该可以使用ElementHost.Child在wform中托管WPF,但是在我的示例代码中找不到添加此变量/函数(缺少某些内容?),System.Windows.Forms.Integration.ElementHost告诉我System.Windows.Forms.Integration丢失了。

在 Winform 中承载 WPF 复合控件

不建议在 WinForms 应用中混合使用 WPF,但Microsoft Windows FormsIntegration 命名空间中提供了 ElementHost。

这是他们工作的更深入的演示混合 WPF 和 Winforms

(对不起,简单的答案我以前没有混合过。

最新更新