我使用 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/