public static void SetParentWindowToNull(this Window window) { if (window.Owner != null) { window.Owner = null; } else { Win32Helper.SetOwner(new WindowInteropHelper(window).Handle, IntPtr.Zero); } }
public static void SetParentToMainWindowOf(this Window window, Visual element) { var wndParent = Window.GetWindow(element); if (wndParent != null) { window.Owner = wndParent; } else { IntPtr parentHwnd; if (GetParentWindowHandle(element, out parentHwnd)) { Win32Helper.SetOwner(new WindowInteropHelper(window).Handle, parentHwnd); } } }