14

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#

Walt Ritscher
  • 6,977
  • 1
  • 28
  • 35
Munashe Tsododo
  • 247
  • 1
  • 5
  • 13
  • 1
    You should edit your question and add the language you are using. – rodrigogq Dec 13 '14 at 19:35
  • Does this answer your question? [ShowDialog() behind the parent window](https://stackoverflow.com/questions/9855954/showdialog-behind-the-parent-window) – StayOnTarget Jul 30 '21 at 17:41

2 Answers2

24

owner can be set but parent is a readonly property.

var w = new Window();
w.Owner = Window.GetWindow(this);
w.Show();
Xilmiki
  • 1,453
  • 15
  • 22
12

on your "Showdialog" object do:

templateWindow.Owner= System.Windows.Application.Current.MainWindow;
templateWindow.ShowDialog();
DiSaSteR
  • 608
  • 6
  • 11