简体   繁体   English

将 WPF Window 添加到 Winforms 应用程序时是否存在陷阱?

[英]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.我在我的解决方案中添加了一个 WPF 项目,其中包含一个项目 - 一个 Winforms 项目。 Then I referenced the WPF project from the Winforms one and added the appropriate references.然后我从 Winforms 一中引用了 WPF 项目并添加了适当的引用。 I then created a new WPF Window in the original Winforms project and opened it from within a button event handler.然后,我在原始 Winforms 项目中创建了一个新的 WPF Window 并从按钮事件处理程序中打开它。 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?过去在搜索类似的解决方案时,我不记得提到过这个解决方案(只是在解决方案中添加另一个项目),所以我想知道:将 WPF Window 添加到 Winforms 应用程序时是否存在陷阱?

EDIT编辑

I'm not referring to embedding it inside a Form.我不是指将其嵌入到表单中。 Just a separate Window (perhaps instead of the main Form).只是一个单独的 Window (可能代替主窗体)。 And I'm also not referring to challenges that are apparent such as the need to translate Bitmaps to their WPF equivalents.而且我也不是指明显的挑战,例如需要将位图转换为其 WPF 等效项。 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.我只是指没有注意到的陷阱,应用程序编译并似乎运行,但是,例如,稍后在具有不同 DPI 的机器上执行时 - 显示不正确。

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: 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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