wpf窗口顶部的空白

jus*_*fly 5 wpf

在此处输入图片说明

我创建了一个新的wpf窗口并设置了主网格的背景,当我将WindowStyle设置为None时,发现窗口顶部有一个空白区域。如何删除空格?

<Window x:Class="XuanyiRetail.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" WindowStyle="None">
<Grid Background="Bisque">

</Grid>
Run Code Online (Sandbox Code Playgroud)

小智 6

设置这些属性就OK了!

WindowStyle="None"  
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
Run Code Online (Sandbox Code Playgroud)


Bas*_*sti 1

不仅在顶部,而且在其他三个边缘上都有可见的白色边框。

您的项目中必须有一个样式,它定义了类型网格的边距。

类似于 Margin="1,5,1,1"

<Style TargetType="{x:Type Grid}">
   <Setter Property="Margin" Value="1,5,1,1"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

为了确保这是错误的根源,您可以在该窗口中定义一个没有边距的样式。

<Window.Resources>
  <Style x:Key="NoMarginGrid" TargetType="{x:Type Grid}">
    <Setter Property="Margin" Value="0"/>
  </Style>
</Window.Resources>
<Grid Background="Bisque" Style="{StaticResource NoMarginGrid}" >
</Grid>
Run Code Online (Sandbox Code Playgroud)