WPF中控制窗口显示位置的三种方式

首先新建一个WPF工程,在主界面添加一个按钮,并给按钮添加点击事件button1_Click,然后新建一个用于测试弹出位置的窗口TestWindow。
1、在屏幕中间显示,设置window.WindowStartupLocation = WindowStartupLocation.CenterScreen;

private void button1_Click(object sender, RoutedEventArgs e)
{
TestWindow window = new TestWindow();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.ShowDialog();
}

2、在父窗口中间显示,

设置window.WindowStartupLocation = WindowStartupLocation.CenterOwner;,并指定Owner。

private void button1_Click(object sender, RoutedEventArgs e)
{
TestWindow window = new TestWindow();
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.Owner = this;
window.ShowDialog();
}

3、在任意位置显示,设置window.WindowStartupLocation = WindowStartupLocation.Manual;并制定窗口的Left和Top坐标。

private void button1_Click(object sender, RoutedEventArgs e)
{
TestWindow window = new TestWindow();
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Left = ;
window.Top = ;
window.ShowDialog();
}
上一篇:SAS Shortcut Keys


下一篇:WPF 中style文件的引用