10

enter image description here

I created a new wpf window and set the background of the main Grid, I found there is a blank space on the top of window when I set WindowStyle to be None. How to remove the blank space?

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

justinfly
  • 179
  • 2
  • 6
  • 2
    Possible duplicate of [How to remove white strip on top of WPF window with WindowStyle=None?](http://stackoverflow.com/questions/36631165/how-to-remove-white-strip-on-top-of-wpf-window-with-windowstyle-none) – Dour High Arch Apr 14 '16 at 18:46

2 Answers2

6

Set these propertys will be OK!

WindowStyle="None"  
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
李起升
  • 61
  • 1
  • 4
  • AllowsTransparency solved this for me. Any explanation on why/how this works? – Mark Aug 30 '20 at 16:06
  • AllowsTransparency works for me. I like the hint to ResizeMode, otherwise I was not able to re-size my window – KargWare Dec 04 '22 at 13:08
1

Not only on top but also on the three other edges are white borders visible.

There has to be an Style in your Project, which defines a Margin for the Type Grid.

Something like Margin="1,5,1,1"

<Style TargetType="{x:Type Grid}">
   <Setter Property="Margin" Value="1,5,1,1"/>
</Style>

To make sure this is the source of the error you could just define a style without a margin in that window.

<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>
Basti
  • 994
  • 6
  • 11