开发者

How to add a WPF window to a WinForms App

I'm creating a HUD window for inspecting biz entities in my WinForms开发者_如何学Python application.

I wanted to have a completely different style of window (minimize the content area and showing only the TitleBar, no system buttons, etc) so I created a WPF application for this.

The problem is that I want this Window to 'live' inside my WinForms application. I can't just add the WPF as an OwnedForm or set the main Form as the Owner of the WPF window.

So, how can achive this?

EDIT: Thanks to pst I found the answer. Here is the snippet:

System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(_inspector);
WindowInteropHelper inspectorHelper = new WindowInteropHelper(_inspector);
inspectorHelper.Owner = this.Handle;
_inspector.Show();


A WPF Window has a Win32-window handle/context.

See WindowInteropHelper. You can use this with Win32 (or perhaps there is WinForms support?) to set the owner window of the WPF Window. Be aware the handle does not exist until the "source initialized" (?) event.

However, using just WinForms, you may be able to customize the titlebar as much as you need (you can overwrite the drawing itself via Win32, and I think you lose all the control boxes without going this far).

There are lots of google results on this topic if you use the correct keywords.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜