Setting WPF Dialog owner from within WinForms application

I had some WPF dialog that I need to show from older WinForms application, or more precisely from some WinForms UserControl. The problem was to set Owner of that dialog, GetWindow() didn’t work (of course) and leaving dialog without an owner, made it possible to disappear when user switch from application to application. And I didn’t want to show it in task bar either.

Thankfully, there is a very easy way, which, for some reason, I didn’t find quite fast – use WindowInteropHelper class. Here is an example:

   1: MyWpfDialog dialog = new MyWpfDialog();
   2:  
   3: //remember, this is WinForms UserControl and its Handle property is
   4: //actually IntPtr containing Win32 HWND.
   5: new System.Windows.Interop.WindowInteropHelper(dialog).Owner = this.Handle;
   6: dialog.ShowDialog();
Technorati Tags: , ,

posted @ Thursday, July 02, 2009 4:20 PM

Print

Comments on this entry:

# re: Setting WPF Dialog owner from within WinForms application

Left by Dino at 8/17/2009 11:06 AM
Gravatar
Thanks.

Really useful !

# re: Setting WPF Dialog owner from within WinForms application

Left by X at 10/16/2009 12:37 PM
Gravatar
sUPER, tHANX

# Mr

Left by abcd muhammad at 8/8/2011 4:13 PM
Gravatar
Jeep Dispatcher Steering Pump
e WPF dialog that I need to show from older WinForms application, or more precisely from some WinForms UserControl. The problem was to set Owner of that dialog, GetWindow() didn’t work (of course) and leaving dialog without an owner, made it possible to disappear when user switch from a

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 6 and type the answer here:
 

Live Comment Preview: