WPF set parent (Window)
21,899
Solution 1
owner can be set but parent is a readonly property.
var w = new Window();
w.Owner = Window.GetWindow(this);
w.Show();
Solution 2
on your "Showdialog" object do:
templateWindow.Owner= System.Windows.Application.Current.MainWindow;
templateWindow.ShowDialog();
Author by
Munashe Tsododo
Updated on February 22, 2020Comments
-
Munashe Tsododo about 4 years
How do you set the parent of a WPF window when you want to show it as a dialog? Both methods Show() and ShowDialog() don't seem to have that option.
This was possible in Java as you could pass the parent in the constructor. Is it possible in any way in WPF?
EDIT: I'm using C#
-
blearyeye over 5 yearsIn a UserControl, the
Window.GetWindow(this)
doesn't work. This form does.