WPF 设置父级(窗口)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27462682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF set parent (Window)
提问by Munashe Tsododo
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.
当您想将其显示为对话框时,如何设置 WPF 窗口的父级?Show() 和 ShowDialog() 两种方法似乎都没有这个选项。
This was possible in Java as you could pass the parent in the constructor. Is it possible in any way in WPF?
这在 Java 中是可能的,因为您可以在构造函数中传递父级。在 WPF 中有任何可能吗?
EDIT: I'm using C#
编辑:我正在使用 C#
回答by Xilmiki
owner can be set but parent is a readonly property.
owner 可以设置,但 parent 是只读属性。
var w = new Window();
w.Owner = Window.GetWindow(this);
w.Show();
回答by DiSaSteR
on your "Showdialog" object do:
在您的“Showdialog”对象上执行以下操作:
templateWindow.Owner= System.Windows.Application.Current.MainWindow;
templateWindow.ShowDialog();

