如何在屏幕上居中放置 WPF 应用程序? [英] How to center a WPF app on screen?

查看:39
本文介绍了如何在屏幕上居中放置 WPF 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在主屏幕上启动时将我的 WPF 应用程序居中.我知道我必须设置 myWindow.Left 和 myWindow.Top,但我从哪里获得这些值?

我找到了 System.Windows.Forms.Screen.PrimaryScreen,它显然不是 WPF.是否有 WPF 替代方案可以为我提供屏幕分辨率或类似的分辨率?

解决方案

把它放在你的窗口构造函数中

WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

<块引用>

.NET Framework 支持:4、3.5、3.0

.NET Framework 客户端配置文件支持在:4, 3.5 SP1

I want to center my WPF app on startup on the primary screen. I know I have to set myWindow.Left and myWindow.Top, but where do I get the values?

I found System.Windows.Forms.Screen.PrimaryScreen, which is apparently not WPF. Is there a WPF alternative that gives me the screen resolution or something like that?

解决方案

Put this in your window constructor

WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

.NET FrameworkSupported in: 4, 3.5, 3.0

.NET Framework Client ProfileSupported in: 4, 3.5 SP1

这篇关于如何在屏幕上居中放置 WPF 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆