【问题标题】:.Net: How to use a WPF user control in a windows forms application?.Net:如何在 Windows 窗体应用程序中使用 WPF 用户控件?
【发布时间】:2011-02-21 09:00:00
【问题描述】:

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

【问题讨论】:

标签: wpf winforms user-controls


【解决方案1】:

来自 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 用于 WinForms WPF。在设计器中,您可以找到 这个控件在工具箱下面 “WPF 互操作性”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多