<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:root="clr-namespace:ModernWpf"
    xmlns:local="clr-namespace:ModernWpf.Controls"
    xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives">

    <Style x:Key="TitleBarBackButtonStyle" TargetType="primitives:TitleBarButton">
        <Setter Property="Background" Value="{DynamicResource AccentButtonBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource AccentButtonForeground}" />
        <Setter Property="HoverBackground" Value="{DynamicResource AccentButtonBackgroundPointerOver}" />
        <Setter Property="HoverForeground" Value="{DynamicResource AccentButtonForegroundPointerOver}" />
        <Setter Property="PressedBackground" Value="{DynamicResource AccentButtonBackgroundPressed}" />
        <Setter Property="PressedForeground" Value="{DynamicResource AccentButtonForegroundPressed}" />
        <Setter Property="FontSize" Value="12" />
        <Setter Property="Width" Value="48" />
        <Setter Property="Content" Value="M 20 10 L 3.828125 10 L 10.410156 16.582031 L 9 18 L 0 9 L 9 0 L 10.410156 1.416016 L 3.828125 8 L 20 8 Z" />
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <local:FontIconFallback Data="{Binding}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <WindowChrome
        x:Key="DefaultWindowChrome"
        x:Shared="False"
        CaptionHeight="{DynamicResource {x:Static local:TitleBar.HeightKey}}"
        CornerRadius="0"
        GlassFrameThickness="{x:Static WindowChrome.GlassFrameCompleteThickness}"
        UseAeroCaptionButtons="False" />

    <Style x:Key="BaseWindowStyle" TargetType="Window">
        <Setter Property="Foreground" Value="{DynamicResource SystemControlPageTextBaseHighBrush}" />
        <Setter Property="Background" Value="{DynamicResource SystemControlPageBackgroundAltHighBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource WindowBorder}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="UseLayoutRounding" Value="True" />
        <Setter Property="WindowChrome.WindowChrome" Value="{DynamicResource DefaultWindowChrome}" />
        <Setter Property="root:ThemeManager.IsThemeAware" Value="True" />
        <Setter Property="local:TitleBar.Background" Value="Transparent" />
        <Setter Property="local:TitleBar.Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" />
        <Setter Property="local:TitleBar.InactiveBackground" Value="Transparent" />
        <Setter Property="local:TitleBar.InactiveForeground" Value="{DynamicResource SystemControlDisabledBaseMediumLowBrush}" />
        <Setter Property="local:TitleBar.BackButtonStyle" Value="{StaticResource TitleBarBackButtonStyle}" />
        <Setter Property="primitives:WindowHelper.FixMaximizedWindow" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Window">
                    <Border
                        x:Name="LayoutRoot"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="{TemplateBinding Padding}"
                        SnapsToDevicePixels="True">
                        <Grid>
                            <Grid x:Name="ContentGrid">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <primitives:TitleBarControl
                                    Icon="{TemplateBinding Icon}"
                                    Title="{TemplateBinding Title}"
                                    IsActive="{TemplateBinding IsActive}"
                                    Background="{TemplateBinding local:TitleBar.Background}"
                                    Foreground="{TemplateBinding local:TitleBar.Foreground}"
                                    InactiveBackground="{TemplateBinding local:TitleBar.InactiveBackground}"
                                    InactiveForeground="{TemplateBinding local:TitleBar.InactiveForeground}"
                                    Style="{TemplateBinding local:TitleBar.Style}"
                                    ButtonStyle="{TemplateBinding local:TitleBar.ButtonStyle}"
                                    IsIconVisible="{TemplateBinding local:TitleBar.IsIconVisible}"
                                    IsBackButtonVisible="{TemplateBinding local:TitleBar.IsBackButtonVisible}"
                                    IsBackEnabled="{TemplateBinding local:TitleBar.IsBackEnabled}"
                                    BackButtonCommand="{TemplateBinding local:TitleBar.BackButtonCommand}"
                                    BackButtonCommandParameter="{TemplateBinding local:TitleBar.BackButtonCommandParameter}"
                                    BackButtonCommandTarget="{TemplateBinding local:TitleBar.BackButtonCommandTarget}"
                                    BackButtonStyle="{TemplateBinding local:TitleBar.BackButtonStyle}"
                                    ExtendViewIntoTitleBar="{TemplateBinding local:TitleBar.ExtendViewIntoTitleBar}"
                                    Panel.ZIndex="1"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                                <AdornerDecorator
                                    x:Name="AdornerDecorator"
                                    Grid.Row="1">
                                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                </AdornerDecorator>

                                <ResizeGrip
                                    x:Name="WindowResizeGrip"
                                    WindowChrome.ResizeGripDirection="BottomRight"
                                    Grid.Row="1"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Bottom"
                                    IsTabStop="false"
                                    Visibility="Collapsed" />
                            </Grid>

                            <Border
                                x:Name="HighContrastBorder"
                                BorderBrush="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}"
                                BorderThickness="7,1,7,7"
                                IsHitTestVisible="False"
                                Visibility="Collapsed" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsActive" Value="False">
                            <Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{DynamicResource WindowBorderInactive}" />
                            <Setter TargetName="HighContrastBorder" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" />
                        </Trigger>
                        <DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="true">
                            <Setter TargetName="ContentGrid" Property="Margin" Value="7,0,7,7" />
                            <Setter TargetName="HighContrastBorder" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="LayoutRoot" Property="BorderThickness" Value="0" />
                            <Setter TargetName="ContentGrid" Property="Margin" Value="0" />
                            <Setter TargetName="HighContrastBorder" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="local:TitleBar.ExtendViewIntoTitleBar" Value="True">
                            <Setter TargetName="AdornerDecorator" Property="Grid.Row" Value="0" />
                            <Setter TargetName="AdornerDecorator" Property="Grid.RowSpan" Value="2" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                                <Condition Property="WindowState" Value="Normal" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="WindowChrome.WindowChrome" Value="{x:Null}">
                <Setter Property="primitives:WindowHelper.FixMaximizedWindow" Value="False" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="DefaultWindowStyle" TargetType="Window" BasedOn="{StaticResource BaseWindowStyle}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
    </Style>

    <Style TargetType="Window" BasedOn="{StaticResource DefaultWindowStyle}" />

</ResourceDictionary>