WPF window style not being applied

It appears that there is no proper solution to your problem. TargetType in Styles doesn’t manage derived types.
Here are two alternatives :
You can put a key in your style and apply the style to all your Windows.

    <!-- Resource file -->    
    <ResourceDictionary ...>
        <Style TargetType="{x:Type Window}" x:Key="WindowDefaultStyle">
            <!-- .... -->    
        </Style>
    </ResourceDictionary>

    <!-- Window file -->
    <Window Style="{DynamicResource ResourceKey=WindowDefaultStyle}">

Or you can use the BasedOn property of the Style.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:my="clr-namespace:WpfApplication1">
    <Style TargetType="{x:Type Window}" x:Key="BaseStyle">
        <Setter Property="Background" Value="#FF121212"></Setter>
        <Setter Property="Height" Value="768"></Setter>
        <Setter Property="Width" Value="1024"></Setter>
    </Style>

    <!-- Inherit from the BaseStyle and define for the MainWindow class -->
    <Style TargetType="{x:Type my:MainWindow}" BasedOn="{StaticResource ResourceKey=BaseStyle}" />
</ResourceDictionary>

Leave a Comment