Why is setting my WPF Window xaml to WindowStyle="None" not working

I have a pretty simple main window in my C# WPF application and need to set the WindowStyle for a Window to "None", however it just doesn't work. I've even tried to set it programmatically in the constructor and in the Loaded event handler, but it doesn't work. At runtime, it still has a title bar.

Here is my xaml code:

<Window x:Class="WinCal.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"
    mc:Ignorable="d"
    Height="45" Width="580"
    ResizeMode="NoResize"
    WindowStyle="None"
    Style="{DynamicResource StyledWindow}"
    Background="{DynamicResource BrushBackgroundLight}"
    Loaded="Window_Loaded">
<Grid x:Name="gridMainWindow">
    <Grid.RowDefinitions>
        <RowDefinition Height="46"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="20"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Button x:Name="btnExit" Grid.Row="0" Content="x" Width="15" Height="20" HorizontalAlignment="Center" VerticalAlignment="Top" Click="btnExit_Click"/>
    <ToolBar Grid.Row="0" Grid.Column="1" Width="Auto" Height="Auto" HorizontalContentAlignment="Left" Grid.ColumnSpan="2">
        <Button x:Name="btnActions"  Width="32" Height="32" Background="Transparent" ToolTip="Click to open available actions" Click="btnActions_Click">
            <Image Source="Images\setup.png" HorizontalAlignment="Center" VerticalAlignment="Center" Width="32" Height="32" />
            <Button.ContextMenu>
                <ContextMenu Name="contextMenuActions">
                    <MenuItem Header="_Calibrate...">
                        <MenuItem.Icon>
                            <Image Source="Images\Calipers16.png"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="_Measure and Open Files with RF Data Viewer...">
                        <MenuItem.Icon>
                            <Image Source="Images\Measurement.png"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="_Help">
                        <MenuItem.Icon>
                            <Image Source="Images\Help button.png"/>
                        </MenuItem.Icon>
                        <MenuItem Header="_Contents"/>
                        <MenuItem Header="_Index"/>
                        <MenuItem Header="_Search"/>
                        <Separator/>
                        <MenuItem Header="Check For _Updates..."/>
                        <Separator/>
                        <MenuItem Header="_Web..."/>
                        <Separator/>
                        <MenuItem Header="Request Support..."/>
                        <Separator/>
                        <MenuItem Header="_Document Viewer..."/>
                        <MenuItem Header="Copy _Examples to My Documents..."/>
                        <Separator/>
                        <MenuItem Header="_Licensing..."/>
                        <MenuItem Header="_About..."/>
                    </MenuItem>
                </ContextMenu>
            </Button.ContextMenu>
        </Button>
        <Button Margin="0" x:Name="btnNewSystemSetup" Width="40" Height="40" Background="Transparent" ToolTip="Create New System Setup File">
            <Image Source="Images\New Setup.png" HorizontalAlignment="Center" VerticalAlignment="Center" Height="32" Width="32"/>
        </Button>
        <Button Margin="0" x:Name="btnOpenSystemSetup" Width="40" Height="40" Background="Transparent" ToolTip="Open System Setup File">
            <Image Source="Images\Open file.png" HorizontalAlignment="Center" VerticalAlignment="Center" Height="32" Width="32"/>
        </Button>
        <Button Margin="0" x:Name="btnSaveSystemSetup" Width="40" Height="40" Background="Transparent" ToolTip="Save System Setup File">
            <Image Source="Images\Save.png" HorizontalAlignment="Center" VerticalAlignment="Center" Height="32" Width="32"/>
        </Button>
        <Button Margin="0" x:Name="btnMeasure" Width="40" Height="40" Background="Transparent" ToolTip="Measure or open data files with RF Data Viewer">
            <Image Source="Images\Measurement.png" HorizontalAlignment="Center" VerticalAlignment="Center" Height="32" Width="32"/>
        </Button>
    </ToolBar>
</Grid>


Read more here: https://stackoverflow.com/questions/66344078/why-is-setting-my-wpf-window-xaml-to-windowstyle-none-not-working

Content Attribution

This content was originally published by Jeff H at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: