WPF最大化窗口大于屏幕 [英] WPF Maximized Window bigger than screen

查看:59
本文介绍了WPF最大化窗口大于屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 AllowsTransparency="True" WindowStyle="None" 创建 WPF 窗口并通过 this.WindowState = WindowState.Maximized; 最大化它时,窗口变得大于我的屏幕.

When creating a WPF window with AllowsTransparency="True" WindowStyle="None" and maximizing it via this.WindowState = WindowState.Maximized; the Window gets bigger than my screen.

设置 AllowTransparency="False" 时,我的窗口周围有边框,但窗口不会比我的屏幕大.
在我的例子中,我有一个 1920x1080 的屏幕,窗口变成 1934x1094.
在我的 1280x1024 屏幕上,窗口将变为 1294x1038.
无论是否启用 AllowTransparency,Window 仍会变得如此大,但禁用它后它仍能正常工作.

When setting AllowTransparency="False" i have a border around my Window, but the window won't get bigger than my screen.
In my Case I have a 1920x1080 screen and the window becomes 1934x1094.
On my 1280x1024 screen the window will become 1294x1038.
The Window will become still as big as this, whether or not AllowTransparency is enabled or not, yet with it disabled it works properly.

在最大化之前设置 AllowTransparency 不起作用并抛出 InvalidOperationException.

Setting AllowTransparency before maximizing doesen't work and throws an InvalidOperationException.

如何获得没有 Windows 样式边框的 WPF 窗口,但尚未正确最大化?

How to get a WPF window without a Windows-style border, but yet to maximize properly?

推荐答案

参加聚会晚了几年,但只需增加您的 this.borderthickness 以用于 SizeChanged 事件,如下所示:

A couple year late to the party but just increase your this.borderthickness for the SizeChanged event like so:

<Window x:Class="MyApp.MainWindow"
    ResizeMode="CanResize" 
    WindowStyle="SingleBorderWindow"
    SizeChanged="Window_SizeChanged">
....
Code
....
</Window>


public void Window_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        if (this.WindowState == WindowState.Maximized)
        {
            this.BorderThickness = new System.Windows.Thickness(8);
        }
        else
        {
            this.BorderThickness = new System.Windows.Thickness(0);
        }
    }

这篇关于WPF最大化窗口大于屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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