65.9K
CodeProject is changing. Read more.
Home

Set Owner of a WPF Window to a Form

starIconstarIconstarIconstarIconstarIcon

5.00/5 (17 votes)

Nov 27, 2011

CPOL
viewsIcon

45739

Set Owner of a WPF Window to a Form

Use the following method to set the owner of a System.Windows.Window to a System.Windows.Forms.Form:
public static void setOwner(System.Windows.Forms.Form ownerForm, System.Windows.Window window)
        {
            WindowInteropHelper helper = new WindowInteropHelper(window);
            helper.Owner = ownerForm.Handle;
        }
It might be useful when you are developing an application where you are using WinForms and WPF windows together. Note: The window will appear always in front of its owner, I use this to display tips, for example.