代码之家  ›  专栏  ›  技术社区  ›  odiseh

.NET:如何在Windows窗体应用程序中使用WPF用户控件?

  •  1
  • odiseh  · 技术社区  · 15 年前

    如何在Windows窗体应用程序中使用WPF用户控件?

    1 回复  |  直到 15 年前
        1
  •  5
  •   mafu    15 年前

    来自MSDN:

    使用 ElementHost 控件放置 Windows窗体上的wpf uielement 控制或形式。

    例子:

    private void Form1_Load(object sender, EventArgs e)
    {
        // Create the ElementHost control for hosting the
        // WPF UserControl.
        ElementHost host = new ElementHost();
        host.Dock = DockStyle.Fill;
    
        // Create the WPF UserControl.
        HostingWpfUserControlInWf.UserControl1 uc =
            new HostingWpfUserControlInWf.UserControl1();
    
        // Assign the WPF UserControl to the ElementHost control's
        // Child property.
        host.Child = uc;
    
        // Add the ElementHost control to the form's
        // collection of child controls.
        this.Controls.Add(host);
    }
    

    Here 是如何做到这一点的很好的教程。

    名为elementhost的控件用于 wpf在winforms中是什么 WindowsFormsHost用于中的WinForms WPF。在设计师中,你可以找到 下面工具箱中的此控件 “WPF互操作性”。