Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank space at top of wpf window

Tags:

wpf

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>

like image 416
justinfly Avatar asked Nov 24 '15 12:11

justinfly


2 Answers

Set these propertys will be OK!

WindowStyle="None"  
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
like image 188
李起升 Avatar answered Sep 24 '22 07:09

李起升


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>
like image 40
Basti Avatar answered Sep 21 '22 07:09

Basti