Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF set parent (Window)

Tags:

c#

window

wpf

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#

like image 710
Munashe Tsododo Avatar asked Dec 13 '14 19:12

Munashe Tsododo


2 Answers

owner can be set but parent is a readonly property.

var w = new Window();
w.Owner = Window.GetWindow(this);
w.Show();
like image 131
Xilmiki Avatar answered Nov 02 '22 11:11

Xilmiki


on your "Showdialog" object do:

templateWindow.Owner= System.Windows.Application.Current.MainWindow;
templateWindow.ShowDialog();
like image 39
DiSaSteR Avatar answered Nov 02 '22 12:11

DiSaSteR