它是绝对安全的,显示从一个WinForms形式WPF窗口? [英] Is it absolutely safe to display a WPF window from a WinForms form?

查看:127
本文介绍了它是绝对安全的,显示从一个WinForms形式WPF窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个Windows窗体应用程序(.NET 3.5)显示一个WPF窗口。

I would like to display a WPF window from a windows forms application (.NET 3.5).

这code似乎没有在样本项目中的任何问题工作:

This code seems to work without any problem in a sample project:

public partial class WinFormsForm1 : Form
{
    public WinFormsForm1() {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e) {
      WpfWindow1 w = new WpfWindow1();
      w.Show();
    }
}

的形式从开始的Main()作为一个正常的WinForms形式:

The form is started from Main() as a normal Winforms form:

Application.Run(new WinFormsForm1());

这对我来说太容易是真实的。有没有在这有什么缺点?这是安全的吗?

This seems to me too easy to be true. Are there any shortcomings in this? Is this safe to do?

推荐答案

它有一个严重的缺陷:无模式的WPF窗口将<一href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/442782b1-00a1-4e2e-9cc6-ae99b6699126">not获取键盘输入。

It has one serious shortcoming: the modeless WPF window would not get keyboard input.

EnableModelessKeyboardInterop 方法调用所需要的WPF窗口前添加所示:

The EnableModelessKeyboardInterop method call needs to be added before the WPF window is shown:

  WpfWindow1 w = new WpfWindow1();
  System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w);
  w.Show();

ElementHost的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost(v=VS.90).aspx">resides在WindowsFormsIntegration.dll程序的。

延伸阅读:<一href="http://msdn.microsoft.com/en-us/library/aa348549.aspx">http://msdn.microsoft.com/en-us/library/aa348549.aspx

这篇关于它是绝对安全的,显示从一个WinForms形式WPF窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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