<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    mc:Ignorable="d">

    <Style x:Key="CalendarItemStyle" TargetType="{x:Type CalendarItem}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Background" Value="{DynamicResource PopupBackgroundBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource PopupBorderThickness}" />
        <Setter Property="BorderBrush" Value="{DynamicResource PopupBorderBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CalendarItem">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}">
                        <DockPanel Name="PART_Root" LastChildFill="True" >
                            <Button x:Name="PART_PreviousButton" DockPanel.Dock="Left"
                                    FontWeight="Bold" FontFamily="Marlett" Padding="4,2,4,2"
                                    Content="3" Focusable="False" BorderThickness="0"
                                    Background="Transparent"/>
                            <Button x:Name="PART_NextButton" DockPanel.Dock="Right"
                                    FontWeight="Bold" FontFamily="Marlett" Padding="4,2,4,2"
                                    Content="4" BorderThickness="0"
                                    Focusable="False"
                                    Background="Transparent"/>
                            <Button x:Name="PART_HeaderButton" DockPanel.Dock="Top"
                                    Padding="2" Height="30" Focusable="False"
                                    BorderThickness="0" Background="Transparent"/>
                            <Grid>
                                <Grid x:Name="PART_MonthView" Visibility="Visible">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                                <Grid x:Name="PART_YearView"  Visibility="Hidden">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
                            </Grid>
                        </DockPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Calendar}}, Path=DisplayMode}" Value="Year">
                            <Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
                            <Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Calendar}}, Path=DisplayMode}" Value="Decade">
                            <Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
                            <Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CalendarButtonStyle" TargetType="{x:Type CalendarButton}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="FontFamily" Value="{DynamicResource FontFamily}"/>
        <Setter Property="FontSize" Value="{DynamicResource FontSize}" />
        <Setter Property="Width" Value="40" />
        <Setter Property="Height" Value="40" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CalendarButton}">
                    <Border Background="Transparent">
                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                          ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                          ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                        HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                        TextElement.Foreground="{TemplateBinding Foreground}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsInactive" Value="True">
                            <Setter Property="Opacity" Value="0.5" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="{DynamicResource GlyphBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="FontFamily" Value="{DynamicResource FontFamily}"/>
        <Setter Property="FontSize" Value="{DynamicResource FontSize}" />
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Width" Value="40" />
        <Setter Property="Height" Value="40" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                    <Border Background="Transparent">
                        <ContentPresenter
                        Content="{TemplateBinding ContentControl.Content}"
                        ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                        ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                        HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        </ContentPresenter>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsToday" Value="True">
                            <Setter Property="Foreground" Value="{DynamicResource GlyphBrush}" />
                        </Trigger>
                        <Trigger Property="IsInactive" Value="True">
                            <Setter Property="Foreground" Value="{DynamicResource TextBrushDarker}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Foreground" Value="{DynamicResource GlyphBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="{DynamicResource GlyphBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CalendarStyle" TargetType="{x:Type Calendar}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="CalendarDayButtonStyle" Value="{DynamicResource CalendarDayButtonStyle}"/>
        <Setter Property="CalendarButtonStyle" Value="{DynamicResource CalendarButtonStyle}"/>
        <Setter Property="Background" Value="{DynamicResource PopupBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Calendar">
                    <Grid Name="PART_Root">
                        <CalendarItem Name="PART_CalendarItem"
                                      Style="{DynamicResource CalendarItemStyle}"
                                      VerticalAlignment="Center" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type DatePicker}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="TextBlock.FontFamily" Value="{DynamicResource FontFamily}" />
        <Setter Property="TextBlock.FontSize" Value="{DynamicResource FontSize}" />
        <Setter Property="TextBlock.Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="TextBlock.Background" Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="CalendarStyle" Value="{StaticResource CalendarStyle}" />
        <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource ControlBorderThickness}" />
        <Setter Property="Padding" Value="3" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DatePicker">
                    <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{DynamicResource ControlCornerRadius}"
                            Padding="{TemplateBinding Padding}">
                        <DockPanel>
                            <Popup x:Name="PART_Popup" StaysOpen="False"
                                   AllowsTransparency="True" Placement="Bottom"
                                   PlacementTarget="{Binding ElementName=PART_TextBox}" />
                            <ToggleButton x:Name="PART_Button" DockPanel.Dock="Right" Content="🗓"
                                          BorderThickness="0" Padding="5,0,5,0"
                                          IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <DatePickerTextBox x:Name="PART_TextBox" DockPanel.Dock="Left"
                                               Background="Transparent" BorderThickness="0"/>
                        </DockPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_TextBox"  Property="IsFocused" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource GlyphBrush}" TargetName="Border" />
                        </Trigger>
                        <Trigger SourceName="PART_Button"  Property="IsFocused" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource GlyphBrush}" TargetName="Border" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource GlyphBrush}" TargetName="Border" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type DatePickerTextBox}" BasedOn="{StaticResource BaseStyle}">
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="AllowDrop" Value="True" />
        <Setter Property="CaretBrush" Value="{DynamicResource TextBrush}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}"/>
        <Setter Property="BorderThickness" Value="{DynamicResource ControlBorderThickness}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                    <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" CornerRadius="{DynamicResource ControlCornerRadius}"
                            Style="{DynamicResource HighlightBorder}">
                        <Grid>
                            <ScrollViewer x:Name="PART_ContentHost"
                                          VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}"
                                          HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>