<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">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <SineEase x:Key="BadgeEase" EasingMode="EaseOut" />
    <Storyboard x:Key="BadgeChangedStoryboard">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
            <EasingDoubleKeyFrame KeyTime="0" Value="1.4" />
            <EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
                                  KeyTime="0:0:0.3"
                                  Value="1" />
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
            <EasingDoubleKeyFrame KeyTime="0" Value="1.4" />
            <EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
                                  KeyTime="0:0:0.3"
                                  Value="1" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

    <Style TargetType="{x:Type controls:Badged}">
        <Setter Property="BadgeBackground" Value="{DynamicResource AccentBaseColorBrush}" />
        <Setter Property="BadgeChangedStoryboard" Value="{StaticResource BadgeChangedStoryboard}" />
        <Setter Property="BadgeForeground" Value="{DynamicResource IdealForegroundColorBrush}" />
        <Setter Property="BadgePlacementMode" Value="TopRight" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:Badged}">
                    <Grid>
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Content="{TemplateBinding Content}"
                                              ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                        <Border x:Name="PART_BadgeContainer"
                                MinWidth="18"
                                MinHeight="18"
                                Padding="2"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top"
                                Background="{TemplateBinding BadgeBackground}"
                                CornerRadius="9"
                                RenderTransformOrigin=".5,.5"
                                TextElement.FontSize="11"
                                TextElement.FontWeight="DemiBold"
                                Visibility="{TemplateBinding IsBadgeSet, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Border.RenderTransform>
                                <ScaleTransform ScaleX="1" ScaleY="1" />
                            </Border.RenderTransform>
                            <ContentControl Margin="1 0 1 0"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Content="{TemplateBinding Badge}"
                                            Focusable="False"
                                            Foreground="{TemplateBinding BadgeForeground}"
                                            IsTabStop="False" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="BadgePlacementMode" Value="TopLeft">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Top" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="Top">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Center" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Top" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="TopRight">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Right" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Top" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="Right">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Right" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Center" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="BottomRight">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Right" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="Bottom">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Center" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="BottomLeft">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="BadgePlacementMode" Value="Left">
                            <Setter TargetName="PART_BadgeContainer" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="PART_BadgeContainer" Property="VerticalAlignment" Value="Center" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_BadgeContainer" Property="Background" Value="{DynamicResource ResourceKey=MahApps.Metro.Brushes.Badged.DisabledBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
    </Style>

</ResourceDictionary>