<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="../Border.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <SineEase x:Key="SineEaseOut" EasingMode="EaseOut" />

    <ControlTemplate x:Key="BadgeTextTemplate" TargetType="controls:Badge">
        <controls:SimplePanel>
            <ContentPresenter />
            <Border x:Name="Border" RenderTransformOrigin="0.5 0.5" Style="{StaticResource BorderCircular}" Margin="{TemplateBinding BadgeMargin}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                <Border.RenderTransform>
                    <ScaleTransform />
                </Border.RenderTransform>
                <ContentPresenter ContentSource="Text" Margin="{TemplateBinding Padding}" />
            </Border>
        </controls:SimplePanel>
        <ControlTemplate.Triggers>
            <EventTrigger RoutedEvent="controls:Badge.ValueChanged">
                <BeginStoryboard>
                    <Storyboard AutoReverse="True">
                        <DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" BeginTime="0" Duration="0:0:.1" From="1" To="1.2" EasingFunction="{StaticResource SineEaseOut}" />
                        <DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" BeginTime="0" Duration="0:0:.1" From="1" To="1.2" EasingFunction="{StaticResource SineEaseOut}" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="BadgeDotTemplate" TargetType="controls:Badge">
        <controls:SimplePanel>
            <ContentPresenter />
            <Border Margin="{TemplateBinding BadgeMargin}" Width="10" Height="10" CornerRadius="5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
        </controls:SimplePanel>
    </ControlTemplate>

    <ControlTemplate x:Key="BadgeProcessingTemplate" TargetType="controls:Badge">
        <controls:SimplePanel>
            <ContentPresenter />
            <Ellipse Height="10" Width="10" Fill="{TemplateBinding Background}" RenderTransformOrigin="0.5 0.5" Margin="{TemplateBinding BadgeMargin}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Ellipse.OpacityMask>
                    <RadialGradientBrush>
                        <GradientStop Offset="0" Color="Transparent" />
                        <GradientStop Offset="1" Color="Black" />
                    </RadialGradientBrush>
                </Ellipse.OpacityMask>
                <Ellipse.RenderTransform>
                    <ScaleTransform />
                </Ellipse.RenderTransform>
                <Ellipse.Triggers>
                    <EventTrigger RoutedEvent="Loaded">
                        <BeginStoryboard>
                            <Storyboard RepeatBehavior="Forever">
                                <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" BeginTime="0" Duration="0:0:1" From="1" To="2" EasingFunction="{StaticResource SineEaseOut}" />
                                <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" BeginTime="0" Duration="0:0:1" From="1" To="2" EasingFunction="{StaticResource SineEaseOut}" />
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0:0:1" From="1" To="0" EasingFunction="{StaticResource SineEaseOut}" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Ellipse.Triggers>
            </Ellipse>
            <Border Margin="{TemplateBinding BadgeMargin}" Width="10" Height="10" CornerRadius="5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
        </controls:SimplePanel>
    </ControlTemplate>

    <Style x:Key="BadgeBaseStyle" TargetType="controls:Badge">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}" />
        <Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{DynamicResource RegionBrush}" />
        <Setter Property="Padding" Value="6,2" />
        <Setter Property="Template" Value="{StaticResource BadgeTextTemplate}" />
        <Setter Property="HorizontalContentAlignment" Value="Right" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="BadgeMargin" Value="0,-10,-10,0" />
        <Style.Triggers>
            <Trigger Property="Status" Value="Dot">
                <Setter Property="Template" Value="{StaticResource BadgeDotTemplate}" />
                <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
                <Setter Property="BadgeMargin" Value="0,-5,-5,0" />
            </Trigger>
            <Trigger Property="Status" Value="Processing">
                <Setter Property="Template" Value="{StaticResource BadgeProcessingTemplate}" />
                <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
                <Setter Property="BadgeMargin" Value="0,-5,-5,0" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>