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

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

问题描述

我使用 WindowChrome 来自定义一个窗口.当我最大化窗口时,边缘会超出屏幕.我使用以下代码来解决这个问题:

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.

如果您希望窗口在最大化时完全可见,只需在网格样式中使用 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天全站免登陆