[英]WPF in Windows Forms
Hi guys, 嗨,大家好,
I'm working on new project that based on Windows Forms C# pattern. 我正在开发基于Windows Forms C#模式的新项目。 One of the window in my software, need to be designed by WPF, is there any way to use WPF window inside Windows Forms project?
我的软件中的一个窗口,需要由WPF设计,有没有办法在Windows Forms项目中使用WPF窗口?
I mean, when i'm calling to new window i use this code: 我的意思是,当我打电话给新窗口时,我使用此代码:
Windows w = new Windows();
w.Show();
but when i'm trying to it on the WPF class it's throwing me an error that it's not supported. 但是当我在WPF类上尝试它时,它会给我一个错误,它不受支持。
Can i do something like that with the WPF window? 我可以使用WPF窗口执行类似的操作吗?
If you find yourself in need to open a WPF Window from a WinForms program: 如果您发现自己需要从WinForms程序打开WPF窗口:
code snippet: 代码段:
WPFWindow.Window1 wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();
However ensure you have the following using statements: 但是,请确保您具有以下using语句:
using System; //Given
using System.Windows.Forms; //Given
using System.Windows.Forms.Integration; //Not so Given.
Refer: 参考:
How to programmatically create a WPF window in a WinForm application 如何以编程方式在WinForm应用程序中创建WPF窗口
Open a WPF Window from WinForms & link form app with WPF app 使用WPF应用程序从WinForms和链接表单应用程序打开WPF窗口
How to add a WPF window to a WinForms App 如何将WPF窗口添加到WinForms应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.