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();
Share:
21,899
Munashe Tsododo
Author by

Munashe Tsododo

Updated on February 22, 2020

Comments

  • Munashe Tsododo
    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
    blearyeye over 5 years
    In a UserControl, the Window.GetWindow(this) doesn't work. This form does.