wpf – 如何找到最大化窗口的位置?

我需要知道一个最大化的窗口的位置.

WPF窗口具有指定窗口位置的顶和左属性.但是,如果最大化窗口,这些属性将保持窗口的值处于正常状态.

如果您在单屏幕设置中运行,则最大化的位置是(0,0).但是,如果您有多个屏幕不一定是正确的.如果在主屏幕上最大化,窗口将只有位置(0,0).

那么…有没有办法找出一个最大化的窗口的位置(最好是和顶部和左边的属性相同的逻辑单元)?

我终于找到了一个为我工作的解决方案:
private System.Drawing.Rectangle getwindowRectangle()
{
    System.Drawing.Rectangle windowRectangle;

    if (this.WindowState == System.Windows.WindowState.Maximized)
    {
        /* Here is the magic:
         * Use Winforms code to find the Available space on the
         * screen that contained the window 
         * just before it was maximized
         * (Left,Top have their values from normal WindowState)
         */
        windowRectangle = System.Windows.Forms.Screen.GetWorkingArea(
            new System.Drawing.Point((int)this.Left,(int)this.Top));
    }
    else
    {
        windowRectangle = new System.Drawing.Rectangle(
            (int)this.Left,(int)this.Top,(int)this.ActualWidth,(int)this.ActualHeight);
    }

    return windowRectangle;
}

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...