<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBlock.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Themes/Thumb.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <Converters:ThicknessBindingConverter x:Key="ThicknessBindingConverter" />
    <Converters:ThicknessToDoubleConverter x:Key="ThicknessToDoubleConverter" />

    <ControlTemplate x:Key="WindowTemplateKey" TargetType="{x:Type Controls:MetroWindow}">
        <Grid Background="{TemplateBinding Background}"
              LayoutTransform="{Binding LayoutTransform, RelativeSource={RelativeSource TemplatedParent}}"
              RenderTransform="{Binding RenderTransform, RelativeSource={RelativeSource TemplatedParent}}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
              UseLayoutRounding="True">
            <AdornerDecorator>
                <Grid UseLayoutRounding="False">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Left}}" />
                        <!--  icon  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  left window commands  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  title  -->
                        <ColumnDefinition Width="*" />
                        <!--  right window commands  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  min,max,close buttons  -->
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Right}}" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Top}}" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Rectangle x:Name="PART_WindowTitleBackground"
                               Grid.Row="1"
                               Grid.Column="1"
                               Grid.ColumnSpan="5"
                               Fill="{TemplateBinding WindowTitleBrush}"
                               Focusable="False"
                               StrokeThickness="0"
                               Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  icon  -->
                    <ContentControl x:Name="PART_Icon"
                                    Grid.Row="1"
                                    Grid.Column="1"
                                    Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    MinWidth="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    HorizontalContentAlignment="Stretch"
                                    VerticalContentAlignment="Stretch"
                                    Panel.ZIndex="1"
                                    Content="{TemplateBinding Icon}"
                                    ContentTemplate="{TemplateBinding IconTemplate}"
                                    Focusable="False"
                                    Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  the left window commands  -->
                    <ContentPresenter x:Name="PART_LeftWindowCommands"
                                      Grid.Row="1"
                                      Grid.Column="2"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <Controls:MetroThumb x:Name="PART_WindowTitleThumb"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="7"
                                         Style="{StaticResource WindowTitleThumbStyle}"
                                         UseLayoutRounding="True" />
                    <!--  the title bar  -->
                    <Controls:MetroThumbContentControl x:Name="PART_TitleBar"
                                                       Grid.Row="1"
                                                       Grid.Column="3"
                                                       Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                                       HorizontalAlignment="{TemplateBinding TitleAlignment}"
                                                       HorizontalContentAlignment="Stretch"
                                                       VerticalContentAlignment="Stretch"
                                                       Content="{TemplateBinding Title}"
                                                       ContentCharacterCasing="{TemplateBinding TitleCharacterCasing}"
                                                       ContentTemplate="{TemplateBinding TitleTemplate}"
                                                       Focusable="False"
                                                       Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <ContentControl.Foreground>
                            <MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
                                <Binding ElementName="PART_WindowTitleBackground"
                                         Mode="OneWay"
                                         Path="Fill" />
                                <Binding Mode="OneWay"
                                         Path="TitleForeground"
                                         RelativeSource="{RelativeSource TemplatedParent}" />
                            </MultiBinding>
                        </ContentControl.Foreground>
                    </Controls:MetroThumbContentControl>

                    <!--  the right window commands  -->
                    <ContentPresenter x:Name="PART_RightWindowCommands"
                                      Grid.Row="1"
                                      Grid.Column="4"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  the window button commands  -->
                    <ContentPresenter x:Name="PART_WindowButtonCommands"
                                      Grid.Row="1"
                                      Grid.RowSpan="2"
                                      Grid.Column="5"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False" />

                    <!--  the main window content  -->
                    <Controls:MetroContentControl x:Name="PART_Content"
                                                  Grid.Row="2"
                                                  Grid.Column="0"
                                                  Grid.ColumnSpan="7"
                                                  FocusVisualStyle="{x:Null}"
                                                  IsTabStop="False"
                                                  OnlyLoadTransition="True"
                                                  TransitionsEnabled="{TemplateBinding WindowTransitionsEnabled}"
                                                  UseLayoutRounding="True">
                        <ContentPresenter Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Top}}" UseLayoutRounding="False" />
                    </Controls:MetroContentControl>

                    <!--  disables the main content when a modal flyout is shown  -->
                    <Rectangle Name="PART_FlyoutModal"
                               Grid.Row="1"
                               Grid.RowSpan="2"
                               Grid.Column="1"
                               Grid.ColumnSpan="5"
                               Fill="{DynamicResource BlackColorBrush}"
                               Opacity="0.5"
                               Visibility="Hidden" />
                    <Controls:MetroThumb x:Name="PART_FlyoutModalDragMoveThumb"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="7"
                                         Style="{StaticResource WindowTitleThumbStyle}"
                                         Visibility="{Binding ElementName=PART_FlyoutModal, Path=Visibility, Mode=OneWay}" />

                    <!--  flyouts  -->
                    <ContentControl Grid.Row="0"
                                    Grid.RowSpan="3"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="7"
                                    VerticalAlignment="Stretch"
                                    Panel.ZIndex="2"
                                    Content="{Binding Flyouts, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    Focusable="False"
                                    KeyboardNavigation.TabNavigation="None" />

                    <!--  inactive dialog container  -->
                    <Grid x:Name="PART_MetroInactiveDialogsContainer"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="3"
                          FocusVisualStyle="{x:Null}" />

                    <!--  overlay effect container  -->
                    <Grid x:Name="PART_OverlayBox"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="4"
                          Background="{TemplateBinding OverlayBrush}"
                          FocusVisualStyle="{x:Null}"
                          Focusable="False"
                          Opacity="0"
                          Visibility="Hidden" />

                    <!--  active dialog container  -->
                    <Grid x:Name="PART_MetroActiveDialogContainer"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="5"
                          FocusVisualStyle="{x:Null}" />
                </Grid>
            </AdornerDecorator>

            <Border x:Name="PART_Border"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Background="{x:Null}"
                    BorderBrush="{TemplateBinding GlowBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    UseLayoutRounding="True" />
            <ResizeGrip x:Name="WindowResizeGrip"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Bottom"
                        IsTabStop="False"
                        UseLayoutRounding="True"
                        Visibility="Collapsed" />
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="ShowDialogsOverTitleBar" Value="False">
                <Setter TargetName="PART_MetroActiveDialogContainer" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_MetroActiveDialogContainer" Property="Grid.RowSpan" Value="1" />
                <Setter TargetName="PART_MetroInactiveDialogsContainer" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_MetroInactiveDialogsContainer" Property="Grid.RowSpan" Value="1" />
                <Setter TargetName="PART_OverlayBox" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_OverlayBox" Property="Grid.RowSpan" Value="1" />
            </Trigger>

            <Trigger Property="UseNoneWindowStyle" Value="True">
                <Setter TargetName="PART_FlyoutModalDragMoveThumb" Property="Grid.RowSpan" Value="2" />
                <Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
            </Trigger>
            <Trigger Property="ShowTitleBar" Value="False">
                <Setter TargetName="PART_FlyoutModalDragMoveThumb" Property="Grid.RowSpan" Value="2" />
                <Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
            </Trigger>
            <!--  handle active/inactive state  -->
            <!--<Trigger Property="IsActive" Value="False">
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=NonActiveGlowBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                <Setter TargetName="PART_WindowTitleBackground" Property="Fill" Value="{Binding Path=NonActiveWindowTitleBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </Trigger>-->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsActive" Value="False" />
                    <Condition Property="GlowBrush" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=NonActiveBorderBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsActive" Value="True" />
                    <Condition Property="GlowBrush" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=BorderBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </MultiTrigger>
            <!--  no icon and no icon content template -> collapse the icon content control  -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon" Value="{x:Null}" />
                    <Condition Property="IconTemplate" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Icon" Property="MinWidth" Value="0" />
                <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
            </MultiTrigger>
            <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>

    <ControlTemplate x:Key="CenterWindowTemplateKey" TargetType="{x:Type Controls:MetroWindow}">
        <Grid Background="{TemplateBinding Background}"
              LayoutTransform="{Binding LayoutTransform, RelativeSource={RelativeSource TemplatedParent}}"
              RenderTransform="{Binding RenderTransform, RelativeSource={RelativeSource TemplatedParent}}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
              UseLayoutRounding="True">
            <AdornerDecorator>
                <Grid UseLayoutRounding="False">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Left}}" />
                        <!--  icon  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  left window commands  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  title  -->
                        <ColumnDefinition Width="*" />
                        <!--  right window commands  -->
                        <ColumnDefinition Width="Auto" />
                        <!--  min,max,close buttons  -->
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Right}}" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Top}}" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Rectangle x:Name="PART_WindowTitleBackground"
                               Grid.Row="1"
                               Grid.Column="1"
                               Grid.ColumnSpan="5"
                               Fill="{TemplateBinding WindowTitleBrush}"
                               Focusable="False"
                               StrokeThickness="0"
                               Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  icon  -->
                    <ContentControl x:Name="PART_Icon"
                                    Grid.Row="1"
                                    Grid.Column="1"
                                    Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    MinWidth="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    HorizontalContentAlignment="Stretch"
                                    VerticalContentAlignment="Stretch"
                                    Panel.ZIndex="1"
                                    Content="{TemplateBinding Icon}"
                                    ContentTemplate="{TemplateBinding IconTemplate}"
                                    Focusable="False"
                                    Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  the left window commands  -->
                    <ContentPresenter x:Name="PART_LeftWindowCommands"
                                      Grid.Row="1"
                                      Grid.Column="2"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <Controls:MetroThumb x:Name="PART_WindowTitleThumb"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="7"
                                         Style="{StaticResource WindowTitleThumbStyle}"
                                         UseLayoutRounding="True" />
                    <!--  the title bar  -->
                    <Controls:MetroThumbContentControl x:Name="PART_TitleBar"
                                                       Grid.Row="1"
                                                       Grid.Column="1"
                                                       Grid.ColumnSpan="5"
                                                       Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                                       HorizontalAlignment="{TemplateBinding TitleAlignment}"
                                                       HorizontalContentAlignment="Center"
                                                       VerticalContentAlignment="Center"
                                                       Content="{TemplateBinding Title}"
                                                       ContentCharacterCasing="{TemplateBinding TitleCharacterCasing}"
                                                       ContentTemplate="{TemplateBinding TitleTemplate}"
                                                       Focusable="False"
                                                       Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <ContentControl.Foreground>
                            <MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
                                <Binding ElementName="PART_WindowTitleBackground"
                                         Mode="OneWay"
                                         Path="Fill" />
                                <Binding Mode="OneWay"
                                         Path="TitleForeground"
                                         RelativeSource="{RelativeSource TemplatedParent}" />
                            </MultiBinding>
                        </ContentControl.Foreground>
                    </Controls:MetroThumbContentControl>

                    <!--  the right window commands  -->
                    <ContentPresenter x:Name="PART_RightWindowCommands"
                                      Grid.Row="1"
                                      Grid.Column="4"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!--  the window button commands  -->
                    <ContentPresenter x:Name="PART_WindowButtonCommands"
                                      Grid.Row="1"
                                      Grid.RowSpan="2"
                                      Grid.Column="5"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      VerticalAlignment="Top"
                                      Panel.ZIndex="1"
                                      Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Focusable="False" />

                    <!--  the main window content  -->
                    <Controls:MetroContentControl x:Name="PART_Content"
                                                  Grid.Row="2"
                                                  Grid.Column="0"
                                                  Grid.ColumnSpan="7"
                                                  FocusVisualStyle="{x:Null}"
                                                  IsTabStop="False"
                                                  OnlyLoadTransition="True"
                                                  TransitionsEnabled="{TemplateBinding WindowTransitionsEnabled}"
                                                  UseLayoutRounding="True">
                        <ContentPresenter Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static Converters:ThicknessSideType.Top}}" UseLayoutRounding="False" />
                    </Controls:MetroContentControl>

                    <!--  disables the main content when a modal flyout is shown  -->
                    <Rectangle Name="PART_FlyoutModal"
                               Grid.Row="1"
                               Grid.RowSpan="2"
                               Grid.Column="1"
                               Grid.ColumnSpan="5"
                               Fill="{DynamicResource BlackColorBrush}"
                               Opacity="0.5"
                               Visibility="Hidden" />
                    <Controls:MetroThumb x:Name="PART_FlyoutModalDragMoveThumb"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="7"
                                         Style="{StaticResource WindowTitleThumbStyle}"
                                         Visibility="{Binding ElementName=PART_FlyoutModal, Path=Visibility, Mode=OneWay}" />

                    <!--  flyouts  -->
                    <ContentControl Grid.Row="0"
                                    Grid.RowSpan="3"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="7"
                                    VerticalAlignment="Stretch"
                                    Panel.ZIndex="2"
                                    Content="{Binding Flyouts, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    Focusable="False"
                                    KeyboardNavigation.TabNavigation="None" />

                    <!--  inactive dialog container  -->
                    <Grid x:Name="PART_MetroInactiveDialogsContainer"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="3"
                          FocusVisualStyle="{x:Null}" />

                    <!--  overlay effect container  -->
                    <Grid x:Name="PART_OverlayBox"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="4"
                          Background="{TemplateBinding OverlayBrush}"
                          FocusVisualStyle="{x:Null}"
                          Focusable="False"
                          Opacity="0"
                          Visibility="Hidden" />

                    <!--  active dialog container  -->
                    <Grid x:Name="PART_MetroActiveDialogContainer"
                          Grid.Row="1"
                          Grid.RowSpan="2"
                          Grid.Column="1"
                          Grid.ColumnSpan="5"
                          Panel.ZIndex="5"
                          FocusVisualStyle="{x:Null}" />
                </Grid>
            </AdornerDecorator>

            <Border x:Name="PART_Border"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Background="{x:Null}"
                    BorderBrush="{TemplateBinding GlowBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    UseLayoutRounding="True" />
            <ResizeGrip x:Name="WindowResizeGrip"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Bottom"
                        IsTabStop="False"
                        UseLayoutRounding="True"
                        Visibility="Collapsed" />
        </Grid>

        <ControlTemplate.Resources>
            <Storyboard x:Key="OverlayFastSemiFadeIn"
                        AccelerationRatio=".97"
                        BeginTime="0:0:0"
                        SpeedRatio="2.7"
                        Storyboard.TargetProperty="Opacity">
                <DoubleAnimation To=".7" />
            </Storyboard>
            <Storyboard x:Key="OverlayFastSemiFadeOut"
                        AccelerationRatio=".97"
                        BeginTime="0:0:0"
                        SpeedRatio="2.7"
                        Storyboard.TargetProperty="Opacity">
                <DoubleAnimation To="0.0" />
            </Storyboard>
        </ControlTemplate.Resources>

        <ControlTemplate.Triggers>
            <Trigger Property="ShowDialogsOverTitleBar" Value="False">
                <Setter TargetName="PART_MetroActiveDialogContainer" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_MetroActiveDialogContainer" Property="Grid.RowSpan" Value="1" />
                <Setter TargetName="PART_MetroInactiveDialogsContainer" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_MetroInactiveDialogsContainer" Property="Grid.RowSpan" Value="1" />
                <Setter TargetName="PART_OverlayBox" Property="Grid.Row" Value="2" />
                <Setter TargetName="PART_OverlayBox" Property="Grid.RowSpan" Value="1" />
            </Trigger>

            <Trigger Property="UseNoneWindowStyle" Value="True">
                <Setter TargetName="PART_FlyoutModalDragMoveThumb" Property="Grid.RowSpan" Value="2" />
                <Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
            </Trigger>
            <Trigger Property="ShowTitleBar" Value="False">
                <Setter TargetName="PART_FlyoutModalDragMoveThumb" Property="Grid.RowSpan" Value="2" />
                <Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
            </Trigger>
            <!--  handle active/inactive state  -->
            <Trigger Property="IsActive" Value="False">
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=NonActiveGlowBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                <Setter TargetName="PART_WindowTitleBackground" Property="Fill" Value="{Binding Path=NonActiveWindowTitleBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsActive" Value="False" />
                    <Condition Property="GlowBrush" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=NonActiveBorderBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsActive" Value="True" />
                    <Condition Property="GlowBrush" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding Path=BorderBrush, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            </MultiTrigger>
            <!--  no icon and no icon content template -> collapse the icon content control  -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon" Value="{x:Null}" />
                    <Condition Property="IconTemplate" Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Icon" Property="MinWidth" Value="0" />
                <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
            </MultiTrigger>
            <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>

    <Storyboard x:Key="OverlayFastSemiFadeIn"
                AccelerationRatio=".97"
                BeginTime="0:0:0"
                SpeedRatio="2.7"
                Storyboard.TargetProperty="Opacity">
        <DoubleAnimation To=".7" />
    </Storyboard>
    <Storyboard x:Key="OverlayFastSemiFadeOut"
                AccelerationRatio=".97"
                BeginTime="0:0:0"
                SpeedRatio="2.7"
                Storyboard.TargetProperty="Opacity">
        <DoubleAnimation To="0.0" />
    </Storyboard>

    <Style TargetType="{x:Type Controls:MetroWindow}">
        <Setter Property="Background" Value="{DynamicResource WhiteBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Foreground" Value="{DynamicResource BlackBrush}" />
        <Setter Property="NonActiveBorderBrush" Value="{DynamicResource NonActiveBorderColorBrush}" />
        <Setter Property="NonActiveGlowBrush" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="NonActiveWindowTitleBrush" Value="{DynamicResource NonActiveWindowTitleColorBrush}" />
        <Setter Property="OverlayBrush" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="OverlayFadeIn" Value="{StaticResource OverlayFastSemiFadeIn}" />
        <Setter Property="OverlayFadeOut" Value="{StaticResource OverlayFastSemiFadeOut}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template" Value="{StaticResource WindowTemplateKey}" />
        <Setter Property="TextElement.FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="TitleForeground" Value="{DynamicResource IdealForegroundColorBrush}" />
        <Setter Property="TitleTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Margin="8 -1 1 0"
                               VerticalAlignment="Center"
                               FontFamily="{DynamicResource HeaderFontFamily}"
                               FontSize="{DynamicResource WindowTitleFontSize}"
                               Text="{TemplateBinding Content}"
                               TextTrimming="CharacterEllipsis" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="WindowTitleBrush" Value="{DynamicResource WindowTitleColorBrush}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Icon, Mode=OneWay, Converter={x:Static Converters:IsNullConverter.Instance}}" Value="False">
                <Setter Property="IconTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Controls:MultiFrameImage Width="{TemplateBinding Width}"
                                                      Height="{TemplateBinding Height}"
                                                      MultiFrameImageMode="{Binding IconScalingMode, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
                                                      RenderOptions.BitmapScalingMode="{Binding IconBitmapScalingMode, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
                                                      RenderOptions.EdgeMode="{Binding IconEdgeMode, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
                                                      Source="{TemplateBinding Content}" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <Trigger Property="TitleAlignment" Value="Center">
                <Setter Property="Template" Value="{StaticResource CenterWindowTemplateKey}" />
            </Trigger>
            <!--
                #1823 try to fix another nasty issue
                WindowState = Maximized
                ResizeMode = NoResize
            -->
            <Trigger Property="ResizeMode" Value="NoResize">
                <Setter Property="Margin" Value="0" />
                <Setter Property="ResizeBorderThickness" Value="0" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>