c# - WPF WindowChrome : Edges of maximized Window are out of the screen

标签 c# wpf xaml .net-4.5 window-chrome

我使用 WindowChrome 自定义窗口。当我最大化窗口时,边缘超出了屏幕。我使用以下代码来解决此问题:

<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>

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

SystemParameters.WindowResizeBorderThickness 包含不正确的值。

最佳答案

WindowChrome 在最大化时基本上会重叠 ResizeBorderThickness 的大小。

如果您希望窗口在最大化时完全可见,只需在您的网格样式中使用 WindowChrome ResizeBorderThickness (5px) 作为 Margin:

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

否则,如果您希望边框的 BorderThickness 不可见 当窗口最大化时,除了网格中的 WindowChrome ResizeBorderThickness (5px) 之外,您还应该使用 Border 的 BorderThickness (2px) 作为 Margin风格。那么 Margin 将是 7px

关于c# - WPF WindowChrome : Edges of maximized Window are out of the screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36725769/

相关文章:

WPF:无法设置焦点

c# - WPF Metro UI 图表 - 负值

c# - SimpleInjector 在 .Net MVC 站点启动时抛出间歇性错误

c# - 如何使用 C# 从 RabbitMQ 中的队列接收单个消息

c# - 如何从 Controller 方法返回多个图像?

c# - WPF:ListView 中列表属性的总和

c# - 如何在UWP ListView中进行分页

c# - 在 C# 中使用 XML 模板的 PDFSharp

c# - 枚举 JumpList 最近的文件?

c# - 从另一个ViewModel访问属性