<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"
                    xmlns:behaviours="clr-namespace:MahApps.Metro.Behaviours"
                    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Shared.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="MetroDatePicker" TargetType="{x:Type DatePicker}">
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CalendarStyle" Value="{DynamicResource MahApps.Metro.Styles.BaseMetroCalendar}" />
        <Setter Property="Controls:ControlsHelper.FocusBorderBrush" Value="{DynamicResource TextBoxFocusBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.MouseOverBorderBrush" Value="{DynamicResource TextBoxMouseOverBorderBrush}" />
        <Setter Property="Controls:TextBoxHelper.ButtonWidth" Value="22" />
        <Setter Property="Controls:TextBoxHelper.IsMonitoring" Value="True" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="MinHeight" Value="26" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Grid x:Name="PART_Root">
                        <Border x:Name="Base"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <Grid x:Name="PART_InnerGrid" Margin="{TemplateBinding Padding}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition x:Name="ButtonColumn" Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition x:Name="ButtonRow" Height="*" />
                            </Grid.RowDefinitions>

                            <Button x:Name="PART_Button"
                                    Grid.RowSpan="2"
                                    Grid.Column="1"
                                    Foreground="{TemplateBinding Foreground}"
                                    IsTabStop="False"
                                    Style="{DynamicResource ChromelessButtonStyle}">
                                <!--  PackIconModern - Calendar14  -->
                                <ContentControl Width="{TemplateBinding Controls:TextBoxHelper.ButtonWidth}"
                                                Height="{TemplateBinding Controls:TextBoxHelper.ButtonWidth}"
                                                Padding="2"
                                                Content="M34,52H31V38.5C29.66,39.9 28.16,40.78 26.34,41.45V37.76C27.3,37.45 28.34,36.86 29.46,36C30.59,35.15 31.36,34.15 31.78,33H34V52M45,52V48H37V45L45,33H48V45H50V48H48V52H45M45,45V38.26L40.26,45H45M18,57V23H23V20A2,2 0 0,1 25,18H29C30.11,18 31,18.9 31,20V23H45V20A2,2 0 0,1 47,18H51C52.11,18 53,18.9 53,20V23H58V57H18M21,54H55V31H21V54M48.5,20A1.5,1.5 0 0,0 47,21.5V24.5A1.5,1.5 0 0,0 48.5,26H49.5C50.34,26 51,25.33 51,24.5V21.5A1.5,1.5 0 0,0 49.5,20H48.5M26.5,20A1.5,1.5 0 0,0 25,21.5V24.5A1.5,1.5 0 0,0 26.5,26H27.5A1.5,1.5 0 0,0 29,24.5V21.5A1.5,1.5 0 0,0 27.5,20H26.5Z"
                                                Style="{DynamicResource PathIconContentControlStyle}" />
                            </Button>

                            <DatePickerTextBox x:Name="PART_TextBox"
                                               Grid.Row="1"
                                               Grid.Column="0"
                                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                               Controls:TextBoxHelper.Watermark="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.Watermark), Mode=OneWay}"
                                               Controls:TextBoxHelper.WatermarkAlignment="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.WatermarkAlignment), Mode=OneWay}"
                                               Controls:TextBoxHelper.WatermarkTrimming="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.WatermarkTrimming), Mode=OneWay}"
                                               CaretBrush="{DynamicResource BlackBrush}"
                                               Focusable="{TemplateBinding Focusable}"
                                               FontSize="{TemplateBinding FontSize}"
                                               Foreground="{TemplateBinding Foreground}"
                                               SelectionBrush="{DynamicResource HighlightBrush}">
                                <i:Interaction.Behaviors>
                                    <behaviours:DatePickerTextBoxBehavior />
                                </i:Interaction.Behaviors>
                            </DatePickerTextBox>

                            <ContentControl x:Name="PART_FloatingMessageContainer"
                                            Grid.Row="0"
                                            Grid.Column="0"
                                            Style="{DynamicResource FloatingMessageContainerStyle}">
                                <ContentControl.Height>
                                    <MultiBinding Converter="{Converters:MathMultiplyConverter}">
                                        <Binding ElementName="PART_FloatingMessage"
                                                 Mode="OneWay"
                                                 Path="ActualHeight" />
                                        <Binding ElementName="PART_FloatingMessageContainer"
                                                 Mode="OneWay"
                                                 Path="Opacity" />
                                    </MultiBinding>
                                </ContentControl.Height>
                                <TextBlock x:Name="PART_FloatingMessage"
                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                           Foreground="{TemplateBinding Foreground}"
                                           Style="{DynamicResource MetroAutoCollapsingTextBlock}"
                                           Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                           TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                           TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}">
                                    <TextBlock.RenderTransform>
                                        <TranslateTransform x:Name="FloatingMessageTransform">
                                            <TranslateTransform.Y>
                                                <MultiBinding Converter="{Converters:MathSubtractConverter}">
                                                    <Binding ElementName="PART_FloatingMessage"
                                                             Mode="OneWay"
                                                             Path="ActualHeight" />
                                                    <Binding ElementName="PART_FloatingMessageContainer"
                                                             Mode="OneWay"
                                                             Path="ActualHeight" />
                                                </MultiBinding>
                                            </TranslateTransform.Y>
                                        </TranslateTransform>
                                    </TextBlock.RenderTransform>
                                </TextBlock>
                            </ContentControl>

                            <Popup x:Name="PART_Popup"
                                   Grid.Row="1"
                                   Grid.Column="0"
                                   AllowsTransparency="True"
                                   Placement="Bottom"
                                   PlacementTarget="{Binding ElementName=PART_Root}"
                                   StaysOpen="False" />
                        </Grid>
                        <Border x:Name="DisabledVisualElement"
                                Background="{DynamicResource ControlsDisabledBrush}"
                                BorderBrush="{DynamicResource ControlsDisabledBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                IsHitTestVisible="False"
                                Opacity="0"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Controls:ControlsHelper.IsReadOnly" Value="True">
                            <Setter TargetName="PART_Button" Property="IsEnabled" Value="False" />
                            <Setter TargetName="PART_TextBox" Property="IsReadOnly" Value="True" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
                        </Trigger>
                        <Trigger SourceName="PART_TextBox" Property="IsFocused" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                            <Setter TargetName="PART_FloatingMessage" Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="PART_FloatingMessage" Property="Opacity" Value="1" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="DisabledVisualElement" Property="Opacity" Value="0.6" />
                        </Trigger>
                        <Trigger SourceName="PART_Button" Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger SourceName="PART_Button" Property="IsPressed" Value="True">
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource WhiteBrush}" />
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=IsVisible, RelativeSource={RelativeSource Self}}" Value="True" />
                                <Condition Binding="{Binding Path=(Controls:TextBoxHelper.UseFloatingWatermark), RelativeSource={RelativeSource Self}}" Value="True" />
                                <Condition Binding="{Binding Path=(Controls:TextBoxHelper.HasText), RelativeSource={RelativeSource Self}}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ValidationErrorTemplate}" />
    </Style>

    <Style x:Key="MetroDatePickerTextBox" TargetType="{x:Type DatePickerTextBox}">
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="ContextMenu" Value="{DynamicResource TextBoxMetroContextMenu}" />
        <Setter Property="Controls:TextBoxHelper.IsMonitoring" Value="True" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="EnterGotFocus">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             To=".2"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             To=".2"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                        <Storyboard x:Key="ExitGotFocus">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                        </Storyboard>

                        <Storyboard x:Key="EnterHasText">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             From=".2"
                                             To="0"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             From=".2"
                                             To="0"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                        <Storyboard x:Key="ExitHasText">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid x:Name="PART_InnerGrid" Margin="2">

                        <ScrollViewer x:Name="PART_ContentHost"
                                      VerticalAlignment="Stretch"
                                      Background="{x:Null}"
                                      BorderThickness="0"
                                      FocusVisualStyle="{x:Null}"
                                      IsTabStop="False" />
                        <ContentControl x:Name="PART_Watermark"
                                        Margin="4 0 0 0"
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Controls:TextBoxHelper.WatermarkAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                        Controls:TextBoxHelper.WatermarkTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}"
                                        Focusable="False"
                                        Foreground="{TemplateBinding Foreground}"
                                        IsHitTestVisible="False"
                                        Opacity="0.6"
                                        Visibility="Hidden">
                            <ContentControl.Template>
                                <ControlTemplate TargetType="{x:Type ContentControl}">
                                    <TextBlock HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                               Text="{TemplateBinding Content}"
                                               TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                               TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
                                </ControlTemplate>
                            </ContentControl.Template>
                        </ContentControl>
                        <TextBlock x:Name="PART_Message"
                                   Margin="4 0 0 0"
                                   HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                   Foreground="{TemplateBinding Foreground}"
                                   Style="{DynamicResource MahApps.Metro.Styles.MetroWatermarkTextBlock}"
                                   Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                   TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                   TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls:TextBoxHelper.HasText" Value="False" />
                                <Condition Property="IsFocused" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource EnterGotFocus}" />
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ExitGotFocus}" />
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.Watermark)}" Value="">
                            <Setter TargetName="PART_Watermark" Property="Visibility" Value="Visible" />
                        </DataTrigger>

                        <Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource EnterHasText}" />
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ExitHasText}" />
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>