.Net:如何在 Windows 窗体应用程序中使用 WPF 用户控件? [英] .Net: How to use a WPF user control in a windows forms application?

查看:56
本文介绍了.Net:如何在 Windows 窗体应用程序中使用 WPF 用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to use a WPF user control in a windows forms application?

推荐答案

来自 MSDN:

使用 ElementHost 控件放置一个Windows 窗体上的 WPF UIElement控件或表单.

Use the ElementHost control to place a WPF UIElement on your Windows Forms control or form.

示例:

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 is a nice tutorial how to do that.

名为 ElementHost 的控件用于WinForms 中的 WPF 是什么WindowsFormsHost 用于 WinFormsWPF.在设计器中,您可以找到这个控件在下面的工具箱中WPF 互操作性".

The control called ElementHost is for WPF in WinForms what the WindowsFormsHost was for WinForms in WPF. In the designer, you can find this control in the Toolbox underneath "WPF Interoperability".

这篇关于.Net:如何在 Windows 窗体应用程序中使用 WPF 用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆