Johan's Blog

This and that in a developer's life in general
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

Open a WPF Window from WinForms

If you find yourself in need to open a WPF Window from a WinForms program - this is one way to do it (works for me):

1) Create/Add a new project of type "WPF Custom Control Library"

image

2) Add a new Item of type "Window (WPF)"

image

3) Do your thing with the WPF Window

4) From your WinForms app, create and open the WPF Window:

using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
var wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();

There you go!

The EnableModelessKeyboardInterop() call is necessary to handle keyboard input in the WPF window if loaded from a non-WPF host like WinForms. I understand there are other ways to do this and you can read more about WPF/WinForms interop here.


Cross-posted from my blog at http://weblogs.asp.net/jdanforth
Published den 29 juli 2008 20:31 by johan
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems