WPF WindowChrome:最大化窗口的边缘不在屏幕上 [英] WPF WindowChrome: Edges of maximized Window are out of the screen

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

问题描述

我使用WindowChrome自定义窗口.当我最大化Window时,边缘不在屏幕上.我使用以下代码解决此问题:

I use WindowChrome to customize a Window. When I maximize the Window, then the edges are out of the screen. I use the following code to fix this:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="50" CornerRadius="0" GlassFrameThickness="0" NonClientFrameEdges="None" ResizeBorderThickness="5" UseAeroCaptionButtons="False" />
    </WindowChrome.WindowChrome>

    <Grid>  
        <Grid.Style>
            <Style TargetType="{x:Type Grid}">
                <Setter Property="Margin" Value="0" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
                        <Setter Property="Margin" Value="{x:Static SystemParameters.WindowResizeBorderThickness}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Style>
        <Border BorderThickness="2" BorderBrush="Blue" Background="Yellow" />
    </Grid>

</Window>

我的问题:如何获得正确的像素数,以使边缘不超出屏幕范围.

My problem: How can I get the correct number of pixels, so that the edges are not out of the screen.

SystemParameters.WindowResizeBorderThickness包含的值不正确.

SystemParameters.WindowResizeBorderThickness contains not the correct value.

推荐答案

最大化后,WindowChrome基本上会重叠ResizeBorderThickness大小.

The WindowChrome will basically overlap by the size of ResizeBorderThickness when maximized.

如果您希望窗口完全可见,同时最大化它,则可以使用Grid样式中的WindowChrome ResizeBorderThickness (5px)作为Margin:

If you want your Window completely visible while maximized just use the WindowChrome ResizeBorderThickness (5px) as Margin in your Grid style:

<Setter Property="Margin" Value="5" />


否则,如果您不想看到边框的BorderThickness 当窗口最大化时,除了网格样式的WindowChrome ResizeBorderThickness (5px)之外,还应将Border's BorderThickness (2px)用作Margin.那么Margin将为 7px .


Otherwise if you want your Border's BorderThickness not to be visible while the window is maximized, you should use your Border's BorderThickness (2px) as Margin in addition to the WindowChrome ResizeBorderThickness (5px) in your Grid style. Then the Margin would be 7px.

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

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