简体   繁体   中英

Are there pitfalls when adding a WPF Window to a Winforms app?

I added a WPF project to my solution which contained one project - a Winforms one. Then I referenced the WPF project from the Winforms one and added the appropriate references. I then created a new WPF Window in the original Winforms project and opened it from within a button event handler. It worked fine.

HOWEVER,

in the past when searching for a similar solution I don't remember seeing this solution mentioned (of simply adding another project to the solution) so I was wondering: Are there pitfalls when adding a WPF Window to a Winforms app?

EDIT

I'm not referring to embedding it inside a Form. Just a separate Window (perhaps instead of the main Form). And I'm also not referring to challenges that are apparent such as the need to translate Bitmaps to their WPF equivalents. I'm only referring to pitfalls that are not noticed, where the app compiles and seems to run, but, for example, later when being executed on a machine with a different DPI - shows things incorrectly.

The only obvious pitfall is that the WPF window won't get any keyboard input unless you call ElementHost.EnableModelessKeyboard before you open it in the Windows Forms application:

Window1 window = new Window1();
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(window);
window.Show();

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