<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/Button.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="RubyerCalendarDayButtonStyle" TargetType="CalendarDayButton">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="{DynamicResource DefaultBorderThickness}" />
        <Setter Property="FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource AncestorType=Calendar}}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="MinHeight" Value="25" />
        <Setter Property="MinWidth" Value="30" />
        <Setter Property="Padding" Value="5 2" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllControlCornerRadius}" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="1" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource WhiteForeground}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CalendarDayButton">
                    <Grid>
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         IsActive="{TemplateBinding IsSelected}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource Mode=TemplatedParent}}" />

                        <Ellipse x:Name="TodayDot"
                                 Width="5"
                                 Height="5"
                                 Margin="2"
                                 HorizontalAlignment="Right"
                                 VerticalAlignment="Top"
                                 Fill="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                 Opacity="0" />

                        <ContentPresenter x:Name="NormalText"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

                        <Path x:Name="Blackout"
                              Margin="3"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch"
                              Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633, 11.029181 L15.191895,11.029181 L12.844727,                                 13.999395 L15.21875,17.060919 L12.962891,                                 17.060919 L11.673828,15.256231 L10.352539,                                 17.060919 L8.1396484,17.060919 L10.519043,                                 14.042364 z"
                              Opacity="0"
                              RenderTransformOrigin="0.5,0.5"
                              Stretch="Fill" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.25" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Normal" />
                                <VisualState Name="MouseOver" />
                                <VisualState Name="Pressed" />
                                <VisualState Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="NormalText"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To=".35"
                                                         Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup Name="SelectionStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Unselected" />
                                <VisualState Name="Selected" />
                            </VisualStateGroup>
                            <VisualStateGroup Name="CalendarButtonFocusStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="CalendarButtonFocused" />
                                <VisualState Name="CalendarButtonUnfocused" />
                            </VisualStateGroup>
                            <VisualStateGroup Name="ActiveStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Active" />
                                <VisualState Name="Inactive" />
                            </VisualStateGroup>
                            <VisualStateGroup Name="DayStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="RegularDay" />
                                <VisualState Name="Today">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="TodayDot"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1"
                                                         Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup Name="BlackoutDayStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="NormalDay" />
                                <VisualState Name="BlackoutDay">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Blackout"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To=".2"
                                                         Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="NormalText" Property="TextBlock.Foreground" Value="{Binding Path=(bpa:ControlHelper.FocusedForegroundBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                            <Setter TargetName="TodayDot" Property="Fill" Value="{Binding Path=(bpa:ControlHelper.FocusedForegroundBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                        </Trigger>
                        <Trigger Property="IsInactive" Value="True">
                            <Setter TargetName="NormalText" Property="Opacity" Value="0.4" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style for the months of a year and years of a decade.  -->
    <Style x:Key="RubyerCalendarButtonStyle" TargetType="CalendarButton">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="{DynamicResource DefaultBorderThickness}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource AncestorType=Calendar}}" />
        <Setter Property="MinHeight" Value="50" />
        <Setter Property="MinWidth" Value="50" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllControlCornerRadius}" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="1" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource WhiteForeground}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CalendarButton">
                    <Grid>
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource Mode=TemplatedParent}}" />

                        <ContentPresenter x:Name="NormalText"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerCalendarItemStyle" TargetType="{x:Type CalendarItem}">
        <Setter Property="Margin" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CalendarItem}">
                    <Grid x:Name="PART_Root">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <Border x:Name="headBorder"
                                Background="{Binding Path=(bpa:HeaderHelper.Background), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                CornerRadius="{DynamicResource TopContainerCornerRadius}"
                                TextBlock.FontFamily="{Binding Path=(bpa:HeaderHelper.FontFamily), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                TextBlock.FontSize="{Binding Path=(bpa:HeaderHelper.FontSize), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                TextBlock.FontWeight="{Binding Path=(bpa:HeaderHelper.FontWeight), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                TextBlock.Foreground="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource AncestorType=Calendar}}">
                            <Grid Margin="{Binding Path=(bpa:HeaderHelper.Padding), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                  HorizontalAlignment="{Binding Path=(bpa:HeaderHelper.HorizontalAlignment), RelativeSource={RelativeSource AncestorType=Calendar}}"
                                  VerticalAlignment="{Binding Path=(bpa:HeaderHelper.VerticalAlignment), RelativeSource={RelativeSource AncestorType=Calendar}}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Button x:Name="PART_HeaderButton"
                                        Style="{StaticResource TextButton}"
                                        Grid.Column="0"
                                        Margin="10 0"
                                        Padding="5"
                                        HorizontalContentAlignment="Left"
                                        Focusable="False"
                                        Foreground="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource AncestorType=Calendar}}" />

                                <Button x:Name="PART_PreviousButton"
                                        Style="{StaticResource TextButton}"
                                        Grid.Column="1"
                                        Padding="5"
                                        Focusable="False"
                                        Foreground="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource AncestorType=Calendar}}">
                                    <bpa:Icon Type="ArrowUpSLine" />
                                </Button>

                                <Button x:Name="PART_NextButton"
                                        Style="{StaticResource TextButton}"
                                        Grid.Column="2"
                                        Padding="5"
                                        Focusable="False"
                                        Foreground="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource AncestorType=Calendar}}">
                                    <bpa:Icon Type="ArrowDownSLine" />
                                </Button>
                            </Grid>
                        </Border>

                        <Grid x:Name="PART_MonthView"
                              Grid.Row="1"
                              Margin="5"
                              HorizontalAlignment="Center"
                              Visibility="Visible">
                            <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.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>
                        <Grid x:Name="PART_YearView"
                              Grid.Row="1"
                              Grid.ColumnSpan="3"
                              Margin="5 15 5 5"
                              HorizontalAlignment="Center"
                              Visibility="Hidden">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_Root" Property="Opacity" Value="{StaticResource UnenableOpcity}" />
                        </Trigger>
                        <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
                            <Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
                            <Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" 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="RubyerCalendar" TargetType="{x:Type Calendar}">
        <Setter Property="Background" Value="{DynamicResource FloatBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="CalendarButtonStyle" Value="{StaticResource RubyerCalendarButtonStyle}" />
        <Setter Property="CalendarDayButtonStyle" Value="{StaticResource RubyerCalendarDayButtonStyle}" />
        <Setter Property="CalendarItemStyle" Value="{StaticResource RubyerCalendarItemStyle}" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="Margin" Value="5" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllContainerCornerRadius}" />
        <Setter Property="bpa:HeaderHelper.Background" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:HeaderHelper.Foreground" Value="{DynamicResource WhiteForeground}" />
        <Setter Property="bpa:HeaderHelper.FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource Self}, Converter={StaticResource AddConverter}, ConverterParameter=5}" />
        <Setter Property="bpa:HeaderHelper.FontWeight" Value="Normal" />
        <Setter Property="bpa:HeaderHelper.HorizontalAlignment" Value="Stretch" />
        <Setter Property="bpa:HeaderHelper.VerticalAlignment" Value="Center" />
        <Setter Property="bpa:HeaderHelper.Padding" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Calendar}">
                    <Grid>
                        <Border Background="{TemplateBinding Background}"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                Effect="{DynamicResource AllDirectionEffect3}" />

                        <StackPanel x:Name="PART_Root" HorizontalAlignment="Center">
                            <CalendarItem x:Name="PART_CalendarItem"
                                          Style="{TemplateBinding CalendarItemStyle}"
                                          Background="{TemplateBinding Background}"
                                          BorderBrush="{TemplateBinding BorderBrush}"
                                          BorderThickness="{TemplateBinding BorderThickness}" />
                        </StackPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>