How to remove border of window in WPF?

Viewed 175

This is default window when create project by WPF template :

<Window x:Class="Chaco.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Chaco"
        mc:Ignorable="d"
        BorderThickness="0"
        BorderBrush="Transparent"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button x:Name="ButtonMain" Content="Main" Width="100" Height="50" Background="White">
        </Button>
    </Grid>
</Window>

The default window has black border. enter image description here

How to remove it?

1 Answers

You can set Window.WindowStyle="ToolWindow". You will still have a shadow.

<Window x:Class="Chaco.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Chaco"
        mc:Ignorable="d"
        WindowStyle="ToolWindow"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button x:Name="ButtonMain" Content="Main" Width="100" Height="50" Background="White">
        </Button>
    </Grid>
</Window>

Or you can set WindowChrome.WindowChrome attached property, setting GlassFrameThickness="0" will also remove the shadow:

<WindowChrome.WindowChrome>
    <WindowChrome GlassFrameThickness="0"/>
</WindowChrome.WindowChrome>

Another way would also be to set WindowStyle="None" and AllowsTransparency="True" by the window.

Related