<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/Resources/Default.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="RubyerLoading" TargetType="{x:Type bpa:Loading}">
        <Setter Property="Background" Value="{DynamicResource BorderLight}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="StrokeThickness" Value="5" />
        <Setter Property="Progress" Value="0.01" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Diameter" Value="30" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:Loading}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Grid>
                            <Rectangle x:Name="background"
                                       Width="{TemplateBinding Diameter}"
                                       Height="{TemplateBinding Diameter}"
                                       Stroke="{TemplateBinding Background}"
                                       StrokeThickness="{TemplateBinding StrokeThickness}">
                                <Rectangle.RadiusX>
                                    <MultiBinding Converter="{StaticResource MathDivideConverter}">
                                        <Binding ElementName="background" Path="ActualWidth" />
                                        <Binding Source="2" />
                                    </MultiBinding>
                                </Rectangle.RadiusX>
                                <Rectangle.RadiusY>
                                    <MultiBinding Converter="{StaticResource MathDivideConverter}">
                                        <Binding ElementName="background" Path="ActualHeight" />
                                        <Binding Source="2" />
                                    </MultiBinding>
                                </Rectangle.RadiusY>
                            </Rectangle>

                            <Rectangle x:Name="loading"
                                       Width="{TemplateBinding Diameter}"
                                       Height="{TemplateBinding Diameter}"
                                       RadiusX="{Binding RadiusX, ElementName=background}"
                                       RadiusY="{Binding RadiusY, ElementName=background}"
                                       RenderTransformOrigin="0.5 0.5"
                                       Stroke="{TemplateBinding FocusedBrush}"
                                       StrokeDashArray="{TemplateBinding StrokeDashArray}"
                                       StrokeThickness="{TemplateBinding StrokeThickness}">
                                <Rectangle.RenderTransform>
                                    <RotateTransform x:Name="loadingAngle" Angle="0" />
                                </Rectangle.RenderTransform>
                            </Rectangle>
                        </Grid>

                        <ContentPresenter x:Name="contentPresenter"
                                          Grid.Row="1"
                                          Margin="0 5 0 0"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Focusable="False"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="loadingAngle" Storyboard.TargetProperty="Angle">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="90" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.751" Value="-90" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.501" Value="-180" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:2.25" Value="-90" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:2.251" Value="-270" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:3" Value="-180" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:3.01" Value="0" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Progress">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0.01" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.01" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:2.25" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:3" Value="0.01" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="loading" Storyboard.TargetProperty="FlowDirection">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FlowDirection>LeftToRight</FlowDirection>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.75">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FlowDirection>RightToLeft</FlowDirection>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                            <DiscreteObjectKeyFrame KeyTime="0:0:1.5">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FlowDirection>LeftToRight</FlowDirection>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                            <DiscreteObjectKeyFrame KeyTime="0:0:2.25">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FlowDirection>RightToLeft</FlowDirection>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                            <DiscreteObjectKeyFrame KeyTime="0:0:3">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FlowDirection>LeftToRight</FlowDirection>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="Content" Value="{x:Null}">
                            <Setter TargetName="contentPresenter" Property="Margin" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="WaveLoading" TargetType="{x:Type bpa:Loading}">
        <Setter Property="StrokeThickness" Value="3" />
        <Setter Property="Diameter" Value="15" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:Loading}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel Height="{TemplateBinding Diameter}"
                                    HorizontalAlignment="Center"
                                    Orientation="Horizontal">
                            <Border Width="{TemplateBinding StrokeThickness}"
                                    Margin="1 0"
                                    Background="{TemplateBinding FocusedBrush}"
                                    RenderTransformOrigin="0.5 0.5">
                                <Border.RenderTransform>
                                    <ScaleTransform x:Name="s1" ScaleY="1" />
                                </Border.RenderTransform>
                            </Border>
                            <Border Width="{TemplateBinding StrokeThickness}"
                                    Margin="1 0"
                                    Background="{TemplateBinding FocusedBrush}"
                                    RenderTransformOrigin="0.5 0.5">
                                <Border.RenderTransform>
                                    <ScaleTransform x:Name="s2" ScaleY="1" />
                                </Border.RenderTransform>
                            </Border>
                            <Border Width="{TemplateBinding StrokeThickness}"
                                    Margin="1 0"
                                    Background="{TemplateBinding FocusedBrush}"
                                    RenderTransformOrigin="0.5 0.5">
                                <Border.RenderTransform>
                                    <ScaleTransform x:Name="s3" ScaleY="1" />
                                </Border.RenderTransform>
                            </Border>
                            <Border Width="{TemplateBinding StrokeThickness}"
                                    Margin="1 0"
                                    Background="{TemplateBinding FocusedBrush}"
                                    RenderTransformOrigin="0.5 0.5">
                                <Border.RenderTransform>
                                    <ScaleTransform x:Name="s4" ScaleY="1" />
                                </Border.RenderTransform>
                            </Border>
                            <Border Width="{TemplateBinding StrokeThickness}"
                                    Margin="1 0"
                                    Background="{TemplateBinding FocusedBrush}"
                                    RenderTransformOrigin="0.5 0.5">
                                <Border.RenderTransform>
                                    <ScaleTransform x:Name="s5" ScaleY="1" />
                                </Border.RenderTransform>
                            </Border>
                        </StackPanel>

                        <ContentPresenter x:Name="contentPresenter"
                                          Grid.Row="1"
                                          Margin="0 5 0 0"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Focusable="False"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s1" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="2" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s2" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.125" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="2" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s3" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.325" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="2" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s4" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.625" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="2" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.25" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s5" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.875" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.25" Value="2" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s1" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s2" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s3" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s4" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="s5" Storyboard.TargetProperty="ScaleY">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="Content" Value="{x:Null}">
                            <Setter TargetName="contentPresenter" Property="Margin" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="DotLoading" TargetType="{x:Type bpa:Loading}">
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="Diameter">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource MathAddConverter}">
                    <Binding Path="FontSize" RelativeSource="{RelativeSource Self}" />
                    <Binding Source="20" />
                </MultiBinding>
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:Loading}">
                    <Grid x:Name="root">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <bpa:Icon Width="{TemplateBinding Diameter}"
                                  Height="{TemplateBinding Diameter}"
                                  Foreground="{TemplateBinding FocusedBrush}"
                                  RenderTransformOrigin="0.5 0.5"
                                  Type="Loader2Fill">
                            <bpa:Icon.RenderTransform>
                                <RotateTransform x:Name="angle" Angle="0" />
                            </bpa:Icon.RenderTransform>
                        </bpa:Icon>

                        <ContentPresenter x:Name="contentPresenter"
                                          Grid.Row="1"
                                          Margin="0 5 0 0"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Focusable="False"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="angle" Storyboard.TargetProperty="Angle">
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="360" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="angle" Storyboard.TargetProperty="Angle">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="Content" Value="{x:Null}">
                            <Setter TargetName="contentPresenter" Property="Margin" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>