<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ModernWpf.Controls"
    xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives">

    <Thickness x:Key="CalendarDatePickerTopHeaderMargin">0,0,0,8</Thickness>

    <Style x:Key="DefaultDatePickerTextBoxStyle" TargetType="DatePickerTextBox">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Foreground" Value="{DynamicResource CalendarDatePickerTextForegroundSelected}" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="ContextMenu" Value="{DynamicResource TextControlContextMenu}" />
        <Setter Property="local:TextContextMenu.UsingTextContextMenu" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DatePickerTextBox">
                    <Grid SnapsToDevicePixels="True">
                        <Border
                            x:Name="BorderElement"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}" />
                        <Border
                            x:Name="ContentElement"
                            Padding="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <ContentControl
                            x:Name="PART_Watermark"
                            Focusable="False"
                            IsHitTestVisible="False"
                            Opacity="0"
                            Foreground="{DynamicResource CalendarDatePickerTextForeground}"
                            Margin="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <ScrollViewer
                            x:Name="PART_ContentHost"
                            Style="{DynamicResource TextControlContentHostStyle}"
                            Margin="0"
                            Padding="{TemplateBinding Padding}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="WatermarkStates">
                                <VisualState x:Name="Unwatermarked" />
                                <VisualState x:Name="Watermarked">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="ContentElement"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0"
                                            Duration="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="PART_Watermark"
                                            Storyboard.TargetProperty="Opacity"
                                            To="1"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource CalendarDatePickerTextForegroundDisabled}" />
                            <Setter TargetName="PART_Watermark" Property="Foreground" Value="{DynamicResource CalendarDatePickerTextForegroundDisabled}" />
                        </Trigger>
                        <Trigger Property="IsSelectionActive" Value="True">
                            <Setter TargetName="BorderElement" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThicknessFocused}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
                            <Setter Property="CaretBrush" Value="{DynamicResource TextControlForegroundFocused}" />
                            <Setter TargetName="PART_Watermark" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundFocused}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="DatePickerTextBox" BasedOn="{StaticResource DefaultDatePickerTextBoxStyle}" />

    <Style x:Key="DefaultDatePickerStyle" TargetType="DatePicker">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Foreground" Value="{DynamicResource CalendarDatePickerForeground}" />
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="CalendarStyle" Value="{DynamicResource DatePickerCalendarStyle}" />
        <Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource CalendarDatePickerBorderThemeThickness}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="FocusVisualStyle" Value="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
        <Setter Property="primitives:FocusVisualHelper.UseSystemFocusVisuals" Value="{DynamicResource UseSystemFocusVisuals}" />
        <Setter Property="primitives:FocusVisualHelper.FocusVisualMargin" Value="-3" />
        <Setter Property="primitives:ControlHelper.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
        <Setter Property="primitives:DatePickerHelper.IsEnabled" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DatePicker">
                    <ControlTemplate.Resources>
                        <StreamGeometry x:Key="Calendar">F1 M 7.5 7.5 L 8.75 7.5 L 8.75 8.75 L 7.5 8.75 Z M 11.25 15 L 12.5 15 L 12.5 16.25 L 11.25 16.25 Z M 15 7.5 L 16.25 7.5 L 16.25 8.75 L 15 8.75 Z M 11.25 7.5 L 12.5 7.5 L 12.5 8.75 L 11.25 8.75 Z M 7.5 10 L 8.75 10 L 8.75 11.25 L 7.5 11.25 Z M 3.75 10 L 5 10 L 5 11.25 L 3.75 11.25 Z M 15 10 L 16.25 10 L 16.25 11.25 L 15 11.25 Z M 11.25 10 L 12.5 10 L 12.5 11.25 L 11.25 11.25 Z M 7.5 12.5 L 8.75 12.5 L 8.75 13.75 L 7.5 13.75 Z M 3.75 12.5 L 5 12.5 L 5 13.75 L 3.75 13.75 Z M 15 12.5 L 16.25 12.5 L 16.25 13.75 L 15 13.75 Z M 11.25 12.5 L 12.5 12.5 L 12.5 13.75 L 11.25 13.75 Z M 7.5 15 L 8.75 15 L 8.75 16.25 L 7.5 16.25 Z M 3.75 15 L 5 15 L 5 16.25 L 3.75 16.25 Z M 20 1.25 L 20 18.75 L 0 18.75 L 0 1.25 L 3.75 1.25 L 3.75 0 L 5 0 L 5 1.25 L 15 1.25 L 15 0 L 16.25 0 L 16.25 1.25 Z M 1.25 2.5 L 1.25 5 L 18.75 5 L 18.75 2.5 L 16.25 2.5 L 16.25 3.75 L 15 3.75 L 15 2.5 L 5 2.5 L 5 3.75 L 3.75 3.75 L 3.75 2.5 Z M 18.75 17.5 L 18.75 6.25 L 1.25 6.25 L 1.25 17.5 Z</StreamGeometry>
                    </ControlTemplate.Resources>
                    <Grid SnapsToDevicePixels="True">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <local:ContentPresenterEx
                            x:Name="HeaderContentPresenter"
                            Visibility="{TemplateBinding primitives:ControlHelper.HeaderVisibility}"
                            Content="{TemplateBinding primitives:ControlHelper.Header}"
                            ContentTemplate="{TemplateBinding primitives:ControlHelper.HeaderTemplate}"
                            Margin="{StaticResource CalendarDatePickerTopHeaderMargin}"
                            TextWrapping="Wrap"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <Grid
                            x:Name="PART_Root"
                            Grid.Row="1">
                            <Grid.Resources>
                                <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="Button">
                                    <Grid>
                                        <Rectangle
                                            Fill="{TemplateBinding Background}"
                                            Margin="{TemplateBinding Padding}" />
                                        <local:FontIconFallback
                                            Foreground="{TemplateBinding Foreground}"
                                            FontFamily="{DynamicResource SymbolThemeFontFamily}"
                                            FontSize="12"
                                            Data="{StaticResource Calendar}"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center" />
                                    </Grid>
                                </ControlTemplate>
                            </Grid.Resources>
                            <Border
                                x:Name="Background"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                                MinHeight="{DynamicResource ComboBoxMinHeight}" />
                            <DatePickerTextBox
                                x:Name="PART_TextBox"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{DynamicResource ComboBoxEditableTextPadding}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                Focusable="{TemplateBinding Focusable}"
                                primitives:ControlHelper.CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}" />
                            <Button
                                x:Name="PART_Button"
                                Focusable="False"
                                Background="Transparent"
                                Foreground="{TemplateBinding Foreground}"
                                Width="30"
                                Padding="0,1,1,1"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Stretch"
                                Template="{StaticResource DropDownButtonTemplate}" />
                            <Popup
                                x:Name="PART_Popup"
                                AllowsTransparency="True"
                                Placement="Bottom"
                                StaysOpen="False">
                                <Popup.PlacementRectangle>
                                    <MultiBinding>
                                        <MultiBinding.Converter>
                                            <primitives:PlacementRectangleConverter Margin="0,-4" />
                                        </MultiBinding.Converter>
                                        <Binding ElementName="PART_Root" Path="ActualWidth" />
                                        <Binding ElementName="PART_Root" Path="ActualHeight" />
                                    </MultiBinding>
                                </Popup.PlacementRectangle>
                            </Popup>
                        </Grid>
                        <ContentPresenter
                            x:Name="DescriptionPresenter"
                            Grid.Row="2"
                            Content="{TemplateBinding primitives:ControlHelper.Description}"
                            Visibility="{TemplateBinding primitives:ControlHelper.DescriptionVisibility}"
                            TextElement.Foreground="{DynamicResource SystemControlDescriptionTextForegroundBrush}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_Root" Property="IsMouseOver" Value="True">
                            <Setter TargetName="Background" Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundPointerOver}" />
                            <Setter TargetName="Background" Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushPointerOver}" />
                        </Trigger>

                        <!-- TextBoxFocused -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_TextBox" Property="IsSelectionActive" Value="True" />
                                <Condition SourceName="PART_Button" Property="IsMouseOver" Value="False" />
                                <Condition SourceName="PART_Button" Property="IsPressed" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource ComboBoxEditableDropDownGlyphForeground}" />
                            <Setter TargetName="PART_Button" Property="Padding" Value="0,2,2,2" />
                        </MultiTrigger>
                        <!-- TextBoxFocusedOverlayPointerOver -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_TextBox" Property="IsSelectionActive" Value="True" />
                                <Condition SourceName="PART_Button" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource ComboBoxEditableDropDownGlyphForeground}" />
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource ComboBoxFocusedDropDownBackgroundPointerOver}" />
                            <Setter TargetName="PART_Button" Property="Padding" Value="0,2,2,2" />
                        </MultiTrigger>
                        <!-- TextBoxFocusedOverlayPressed -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_TextBox" Property="IsSelectionActive" Value="True" />
                                <Condition SourceName="PART_Button" Property="IsPressed" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource ComboBoxEditableDropDownGlyphForeground}" />
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource ComboBoxFocusedDropDownBackgroundPointerPressed}" />
                            <Setter TargetName="PART_Button" Property="Padding" Value="0,2,2,2" />
                        </MultiTrigger>
                        <!-- TextBoxOverlayPointerOver -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_TextBox" Property="IsSelectionActive" Value="False" />
                                <Condition SourceName="PART_Button" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource ComboBoxDropDownBackgroundPointerOver}" />
                        </MultiTrigger>
                        <!-- TextBoxOverlayPressed -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_TextBox" Property="IsSelectionActive" Value="False" />
                                <Condition SourceName="PART_Button" Property="IsPressed" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource ComboBoxDropDownBackgroundPointerPressed}" />
                        </MultiTrigger>

                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Background" Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundDisabled}" />
                            <Setter TargetName="Background" Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushDisabled}" />
                            <Setter TargetName="HeaderContentPresenter" Property="Foreground" Value="{DynamicResource CalendarDatePickerHeaderForegroundDisabled}" />
                            <Setter TargetName="PART_TextBox" Property="Foreground" Value="{DynamicResource CalendarDatePickerTextForegroundDisabled}" />
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource CalendarDatePickerCalendarGlyphForegroundDisabled}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="DatePicker" BasedOn="{StaticResource DefaultDatePickerStyle}" />

</ResourceDictionary>