<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:XamlTheme.Controls"
                    xmlns:themes="clr-namespace:XamlTheme"
                    xmlns:shell="clr-namespace:Microsoft.Windows.Shell">

    <Style x:Key="{x:Static themes:ResourceKeys.NormalUserWindowStyleKey}" 
           TargetType="{x:Type controls:UserWindow}">
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome ResizeBorderThickness="4" GlassFrameThickness="0,0,0,1"
                                    CaptionHeight="{Binding CaptionHeight, RelativeSource={RelativeSource AncestorType=controls:UserWindow}}"/>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="MinWidth" Value="100" />
        <Setter Property="MinHeight" Value="100" />
        <Setter Property="BorderBrush" Value="#3498db"/>
        <Setter Property="Foreground" Value="#141414"/>
        <Setter Property="Background" Value="#EFEFF2"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontFamily" Value="Arial,SimSun"/>
        <Setter Property="CaptionForeground" Value="#141414"/>
        <Setter Property="CaptionBackground" Value="#EFEFF2"/>
        <Setter Property="ResizeMode" Value="CanResize"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:UserWindow}">
                    <AdornerDecorator>
                        <Border Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"
                                UseLayoutRounding="True">
                            <Grid x:Name="LayoutRoot">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Grid Grid.Row="0" Background="{TemplateBinding CaptionBackground}" Height="{TemplateBinding CaptionHeight}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Image Grid.Column="0" Source="{TemplateBinding Icon}" VerticalAlignment="Center" WindowChrome.IsHitTestVisibleInChrome="False"/>
                                    <TextBlock x:Name="TitleTextBlock" Grid.Column="1" Margin="5,0,0,0" Text="{TemplateBinding Title}" FontSize="{TemplateBinding CaptionFontSize}" FontWeight="Medium"  VerticalAlignment="Center" Foreground="{TemplateBinding CaptionForeground}" TextTrimming="CharacterEllipsis" WindowChrome.IsHitTestVisibleInChrome="False"/>
                                    <ContentPresenter Grid.Column="2" ContentSource="CaptionContent" WindowChrome.IsHitTestVisibleInChrome="True"/>
                                    <StackPanel Grid.Column="3" Orientation="Horizontal" WindowChrome.IsHitTestVisibleInChrome="True">
                                        <Button x:Name="MiniBtn" Style="{DynamicResource {x:Static themes:ResourceKeys.TitlebarButtonStyleKey}}" Width="37" Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" VerticalContentAlignment="Center" Padding="0,5,0,0" >
                                            <Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                  RenderOptions.EdgeMode="Aliased" Margin="0,0,0,5" Data="F1M0,6L0,9 9,9 9,6 0,6z"/>
                                        </Button>
                                        <Button x:Name="MaxBtn" Style="{DynamicResource {x:Static themes:ResourceKeys.TitlebarButtonStyleKey}}" Width="37" Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}" >
                                            <Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                  RenderOptions.EdgeMode="Aliased" Data="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z"/>
                                        </Button>
                                        <Button x:Name="RestoreBtn" Style="{DynamicResource {x:Static themes:ResourceKeys.TitlebarButtonStyleKey}}" Width="37" Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}" Visibility="Collapsed" >
                                            <Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                  RenderOptions.EdgeMode="Aliased" Data="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z"/>
                                        </Button>
                                        <Button x:Name="CloseBtn" Style="{DynamicResource {x:Static themes:ResourceKeys.TitlebarCloseBtnStyleKey}}" Width="37" Command="{Binding Source={x:Static SystemCommands.CloseWindowCommand}}" IsEnabled="{TemplateBinding IsCloseEnabled}" IsDefault="False" IsCancel="{TemplateBinding IsCloseCanceled}">
                                            <Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                                  RenderOptions.EdgeMode="Aliased" Data="F1M0,0L2,0 5,3 8,0 10,0 6,4 10,8 8,8 5,5 2,8 0,8 4,4 0,0z" />
                                        </Button>
                                    </StackPanel>
                                </Grid>
                                <Border Grid.Row="1" Padding="0">
                                    <ContentPresenter ContentSource="Content"/>
                                </Border>

                                <!-- resize grip -->
                                <ResizeGrip Grid.Row="1" x:Name="ResizeGrip" Width="3" Height="3" Background="Transparent" Opacity="0.3" Foreground="White"
                                            Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
                            </Grid>
                        </Border>
                    </AdornerDecorator> 
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsCloseVisible" Value="False">
                            <Setter TargetName="CloseBtn" Property="Visibility" Value="Collapsed"/>
                        </Trigger>

                        <Trigger Property="HideOriginalTitle" Value="true">
                            <Setter TargetName="TitleTextBlock" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        
                        <Trigger Property="Text" SourceName="TitleTextBlock" Value="{x:Null}">
                            <Setter TargetName="TitleTextBlock" Property="Visibility" Value="Collapsed"/>
                        </Trigger>

                        <Trigger Property="Text" SourceName="TitleTextBlock" Value="">
                            <Setter TargetName="TitleTextBlock" Property="Visibility" Value="Collapsed"/>
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Normal" />
                                <Condition Property="ResizeMode" Value="CanResize" />
                            </MultiTrigger.Conditions>
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Normal" />
                                <Condition Property="ResizeMode" Value="CanMinimize" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="MiniBtn" Property="Visibility" Value="Visible" />
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Normal" />
                                <Condition Property="ResizeMode" Value="NoResize" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="MiniBtn" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Normal" />
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Maximized" />
                                <Condition Property="ResizeMode" Value="CanResize" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="MiniBtn" Property="Visibility" Value="Visible" />
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="RestoreBtn" Property="Visibility" Value="Visible" />
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="7"/>
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="WindowState" Value="Maximized" />
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="RestoreBtn" Property="Visibility" Value="Visible" />
                            <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="7"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>   
</ResourceDictionary>