简体   繁体   中英

WPF in Windows Forms

Hi guys,

I'm working on new project that based on Windows Forms C# pattern. 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?

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.

Can i do something like that with the WPF window?

If you find yourself in need to open a WPF Window from a WinForms program:

  1. Create/Add a new project of type "WPF Custom Control Library"
  2. Add a new Item of type "Window (WPF)"
  3. Do your thing with the WPF Window
  4. From your WinForms app, create and open the WPF Window.

code snippet:

WPFWindow.Window1 wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();

However ensure you have the following using statements:

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
Open a WPF Window from WinForms & link form app with WPF app
How to add a WPF window to a WinForms App

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM