<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ControlTemplates.CustomWindowChrome">
  <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />

  <Style TargetType="{x:Type ResizeGrip}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ResizeGrip}">
          
          <Border Background="Transparent"
            SnapsToDevicePixels="True"
            Width="16"
            Height="16">
            <Rectangle Margin="2">
              <Rectangle.Fill>
                <DrawingBrush Viewport="0,0,4,4"
                  ViewportUnits="Absolute"
                  Viewbox="0,0,8,8"
                  ViewboxUnits="Absolute"
                  TileMode="Tile">
                  <DrawingBrush.Drawing>
                    <DrawingGroup>
                      <DrawingGroup.Children>
                        <GeometryDrawing Brush="#AAA"
                          Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z"/>
                      </DrawingGroup.Children>
                    </DrawingGroup>
                  </DrawingBrush.Drawing>
                </DrawingBrush>
              </Rectangle.Fill>
            </Rectangle>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="CloseButton" TargetType="{x:Type Button}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Canvas>
            <Rectangle Width="15" Height="15" Stroke="Black" RadiusX="3" RadiusY="3">
              <Rectangle.Fill>
                <SolidColorBrush x:Name="myAnimatedBrush" Color="Red" />
              </Rectangle.Fill>
            </Rectangle>
            <Line X1="3" Y1="3" X2="12" Y2="12" Stroke="White" StrokeThickness="2"></Line>
            <Line X1="12" Y1="3" X2="3" Y2="12" Stroke="White" StrokeThickness="2"></Line>
          </Canvas>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>


  <Style x:Key="CustomWindowChrome" TargetType="{x:Type Window}">
    <Setter Property="AllowsTransparency" Value="True"></Setter>
    <Setter Property="WindowStyle" Value="None"></Setter>
    <Setter Property="Background" Value="Transparent"></Setter>
    
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Window}">
          <Border Width="Auto" Height="Auto" Name="windowFrame"    
          BorderBrush="#395984"
          BorderThickness="1"
          CornerRadius="0,20,30,40" >
            <Border.Background>
              <LinearGradientBrush >
                <GradientBrush.GradientStops>
                  <GradientStopCollection>
                    <GradientStop Color="#E7EBF7" Offset="0.0"/>
                    <GradientStop Color="#CEE3FF" Offset="0.5"/>

                  </GradientStopCollection>
                </GradientBrush.GradientStops>
              </LinearGradientBrush>
            </Border.Background>
            <Grid>

              <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
              </Grid.RowDefinitions>

              <TextBlock Margin="1" Padding="5" Text="{TemplateBinding Title}" FontWeight="Bold"
                         MouseLeftButtonDown="titleBar_MouseLeftButtonDown"></TextBlock>
              <Button Style="{StaticResource CloseButton}" HorizontalAlignment="Right" Margin="0,5,25,0"
                      Click="cmdClose_Click"></Button>
              <Border Background="#B5CBEF" Grid.Row="1">
            
                <AdornerDecorator>
                  <ContentPresenter/>
                </AdornerDecorator>
                
              </Border>

              <ContentPresenter Grid.Row="2" Margin="10" 
                                HorizontalAlignment="Center"
                                Content="{TemplateBinding Tag}"></ContentPresenter>
              <!--<TextBlock HorizontalAlignment="Center" Grid.Row="2" Text="{TemplateBinding Tag}" Margin="1,10,1,1" Padding="5"></TextBlock>-->
              <ResizeGrip Name="WindowResizeGrip" Grid.Row="2" Margin="0,0,10,7"
                  HorizontalAlignment="Right"
                  VerticalAlignment="Bottom"
                  Visibility="Collapsed"
                  IsTabStop="false"/>
              
              <Rectangle Grid.Row="1" Grid.RowSpan="3"
       Cursor="SizeWE" Fill="Transparent" Width="5" VerticalAlignment="Stretch" HorizontalAlignment="Right"
                 MouseLeftButtonDown="window_initiateResizeWE"
                 MouseLeftButtonUp="window_endResize"
                 MouseMove="window_Resize"></Rectangle>
            

            <Rectangle Grid.Row="2" 
     Cursor="SizeNS" Fill="Transparent" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
               MouseLeftButtonDown="window_initiateResizeNS"
               MouseLeftButtonUp="window_endResize"
               MouseMove="window_Resize"></Rectangle>
            </Grid>

          </Border>

          <ControlTemplate.Triggers>
            <Trigger Property="ResizeMode" Value="CanResizeWithGrip">
              <Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>