WPF: How do I set the Owner Window of a Dialog shown by a UserControl? WPF: How do I set the Owner Window of a Dialog shown by a UserControl? wpf wpf

WPF: How do I set the Owner Window of a Dialog shown by a UserControl?


Try to use

.Owner = Window.GetWindow(this)


To get the top level window your control is in, assuming there is one:

(Window)PresentationSource.FromVisual(this).RootVisual

To get the main window:

Application.Current.MainWindow


MyWpfDialog dialog = new MyWpfDialog();//remember, this is WinForms UserControl and its Handle property is//actually IntPtr containing Win32 HWND.new System.Windows.Interop.WindowInteropHelper(dialog).Owner = this.Handle;dialog.ShowDialog();