<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:circularProgressBar="clr-namespace:MaterialDesignThemes.Wpf.Converters.CircularProgressBar">
    <Style x:Key="MaterialDesignLinearProgressBar" TargetType="{x:Type ProgressBar}">
        <Setter Property="Foreground" Value="{DynamicResource PrimaryHueDarkBrush}"/>
        <Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueLightBrush}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="OnLoaded">
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="TemplateRoot">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="TemplateRoot">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="TemplateRoot">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid x:Name="TemplateRoot" RenderTransformOrigin="0,0.5" Opacity="0" Height="4">
                        <Grid.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="0" ScaleY="0"/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Grid.RenderTransform>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Determinate"/>
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="Animation">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0.25"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.25"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.25"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="Animation">
                                            <EasingPointKeyFrame KeyTime="0" Value="-0.5,0.5"/>
                                            <EasingPointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/>
                                            <EasingPointKeyFrame KeyTime="0:0:2" Value="1.5,0.5"/>
                                        </PointAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
                        <Rectangle x:Name="PART_Track"/>
                        <Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left">
                            <Rectangle x:Name="Indicator" Fill="{TemplateBinding Foreground}"/>
                            <Rectangle x:Name="Animation" Fill="{TemplateBinding Foreground}" RenderTransformOrigin="0.5,0.5">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsVisible" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource OnLoaded}"/>
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter Property="LayoutTransform" TargetName="TemplateRoot">
                                <Setter.Value>
                                    <RotateTransform Angle="-90"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="true">
                            <Setter Property="Visibility" TargetName="Indicator" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <circularProgressBar:StartPointConverter x:Key="StartPointConverter" />
    <circularProgressBar:ArcSizeConverter x:Key="ArcSizeConverter" />
    <circularProgressBar:ArcEndPointConverter x:Key="ArcEndPointConverter" />
    <circularProgressBar:LargeArcConverter x:Key="LargeArcConverter" />
    <circularProgressBar:RotateTransformConverter x:Key="RotateTransformConverter" />
    <circularProgressBar:RotateTransformCentreConverter x:Key="RotateTransformCentreConverter" />

    <Style x:Key="MaterialDesignCicularProgressBar" TargetType="{x:Type ProgressBar}">
        <Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Width" Value="20" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="IsIndeterminateStoryboard" TargetName="RotateTransform" TargetProperty="Angle" RepeatBehavior="Forever">
                            <DoubleAnimation From="0" To="359" Duration="0:0:2" />
                        </Storyboard>
                        <Storyboard x:Key="IsFullyIndeterminateScaleStoryboard">
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FullyIndeterminateGridScaleTransform"
                                                                   Storyboard.TargetProperty="ScaleX"                                                      
                                                                   RepeatBehavior="Forever">
                                <SplineDoubleKeyFrame KeyTime="0" Value="0.0" />
                                <SplineDoubleKeyFrame KeyTime="0:0:1" Value="1.0" />
                                <SplineDoubleKeyFrame KeyTime="0:0:3" Value="0.0" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="RotateTransform"
                                                     Storyboard.TargetProperty="Angle" 
                                                     RepeatBehavior="Forever"
                                                     From="00" To="359" Duration="0:0:0.75" />
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid x:Name="TemplateRoot" Background="{TemplateBinding Background}" ClipToBounds="False">
                        <Grid x:Name="FullyIndeterminateGrid">
                            <Grid.RenderTransform>
                                <ScaleTransform x:Name="FullyIndeterminateGridScaleTransform" ScaleX="0" />
                            </Grid.RenderTransform>
                        </Grid>
                        <Grid x:Name="PathGrid" Margin="2" />
                        <Canvas>
                            <Path x:Name="Path" Stroke="{TemplateBinding Foreground}" StrokeThickness="3" 
                                          Canvas.Top="2" Canvas.Left="2"
                                          RenderTransformOrigin="0, 0">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathFigure StartPoint="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={StaticResource StartPointConverter}, Mode=OneWay}">
                                            <ArcSegment Size="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={StaticResource ArcSizeConverter}, Mode=OneWay}"                                                             
                                                                SweepDirection="Clockwise"
                                                                >
                                                <ArcSegment.IsLargeArc>
                                                    <MultiBinding Converter="{StaticResource LargeArcConverter}">
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Value" />
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Minimum" />
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Maximum" />
                                                        <Binding ElementName="FullyIndeterminateGridScaleTransform" Path="ScaleX" />
                                                    </MultiBinding>
                                                </ArcSegment.IsLargeArc>
                                                <ArcSegment.Point>
                                                    <MultiBinding Converter="{StaticResource ArcEndPointConverter}">
                                                        <Binding ElementName="PathGrid" Path="ActualWidth" />
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Value" />
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Minimum" />
                                                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Maximum" />
                                                        <Binding ElementName="FullyIndeterminateGridScaleTransform" Path="ScaleX" />
                                                    </MultiBinding>
                                                </ArcSegment.Point>
                                            </ArcSegment>
                                        </PathFigure>
                                    </PathGeometry>
                                </Path.Data>
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform x:Name="RotateTransform"
                                                                 CenterX="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={StaticResource RotateTransformCentreConverter}, Mode=OneWay}" 
                                                                 CenterY="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={StaticResource RotateTransformCentreConverter}, Mode=OneWay}">
                                            <RotateTransform.Angle>
                                                <MultiBinding Converter="{StaticResource RotateTransformConverter}">
                                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Value" />
                                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Minimum" />
                                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Maximum" />
                                                </MultiBinding>
                                            </RotateTransform.Angle>
                                        </RotateTransform>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                        </Canvas>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsIndeterminate" Value="True">
                            <Trigger.EnterActions>
                                <RemoveStoryboard BeginStoryboardName="IsFullyIndeterminateStoryboard" />
                                <BeginStoryboard Storyboard="{StaticResource IsIndeterminateStoryboard}"
                                                         Name="IsIndeterminateStoryboard"/>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <RemoveStoryboard BeginStoryboardName="IsIndeterminateStoryboard" />
                            </Trigger.ExitActions>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsIndeterminate" Value="True" />
                                <Condition Property="Value" Value="0" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <RemoveStoryboard BeginStoryboardName="IsIndeterminateStoryboard" />
                                <BeginStoryboard Storyboard="{StaticResource IsFullyIndeterminateScaleStoryboard}"
                                                         Name="IsFullyIndeterminateStoryboard"/>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <RemoveStoryboard BeginStoryboardName="IsFullyIndeterminateStoryboard" />
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>