首页 文章

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

提问于
浏览
1

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

1 回答

  • 5

    来自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的控件用于WinForms中的WPF,WindowsFormsHost是WPF中WinForms的用途 . 在设计器中,您可以在“WPF互操作性”下的工具箱中找到此控件 .

相关问题