c#wpf根据应用程序打开新窗口

时间:2016-01-26 13:15:54

标签: c# wpf window

我想问一下是否可以打开与主应用程序相关的新窗口?目前我正在使用System.Windows.Window.Left/Right 但它只与桌面有关。

谢谢。

2 个答案:

答案 0 :(得分:3)

您可以使用WindowStartupLocation属性来设置窗口应显示的位置。

在XAML中

<Window WindowStartupLocation="CenterParent">

或代码

WindowStartupLocation=WindowStartupLocation.CenterOwner 

或者您可以设置如下

this.Left = mainWindow.Left + (mainWindow.Width - this.ActualWidth) / 2;
this.Top = mainWindow.Top + (mainWindow.Height - this.ActualHeight) / 2;

答案 1 :(得分:1)

一种简单的方法是使用主窗口的位置。像这样:

OtherWindow other = new OtherWindow();
other.Top = mainWindow.Top + 20;
相关问题