如何将WPF窗口的位置设置在桌面的右下角? [英] How to set the location of WPF window to the bottom right corner of desktop?

查看:1017
本文介绍了如何将WPF窗口的位置设置在桌面的右下角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在窗口启动时在TaskBar的时钟上方显示我的窗口.

I want to show my window on top of the TaskBar's clock when the windows starts.

如何找到桌面右下角的位置?

How can I find the bottom right corner location of my desktop?

我使用此代码在Windows窗体应用程序中运行良好,但在WPF中无法正常工作:

I use this code that works well in windows forms app but does not work correctly in WPF:

var desktopWorkingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Bottom - this.Height;

推荐答案

此代码在WPF中对我来说都适用,并且显示100%和125%

This code works for me in WPF both with Display 100% and 125%

 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
    var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
    this.Left = desktopWorkingArea.Right - this.Width;
    this.Top = desktopWorkingArea.Bottom - this.Height;
 }

简而言之,我使用

System.Windows.SystemParameters.WorkArea

代替

System.Windows.Forms.Screen.PrimaryScreen.WorkingArea

这篇关于如何将WPF窗口的位置设置在桌面的右下角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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