<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="RubyerProgressBar" TargetType="{x:Type ProgressBar}">
        <Setter Property="Background" Value="{DynamicResource BorderLight}" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ProgressBarHelper.Thickness" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid x:Name="TemplateRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="{TemplateBinding FontSize}"
                                   Visibility="{Binding Path=(bpa:ProgressBarHelper.ShowPercent), RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BooleanToVisibleConverter}}">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource GetPercentConverter}">
                                    <Binding Path="Value" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                    <Binding Path="Minimum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                    <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <Grid Grid.Row="1" Height="{Binding Path=(bpa:ProgressBarHelper.Thickness), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                            <Rectangle x:Name="PART_Track" />
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}" />
                            <Grid x:Name="PART_Indicator"
                                  HorizontalAlignment="Left"
                                  ClipToBounds="true">
                                <Rectangle x:Name="Indicator" Fill="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                <Rectangle x:Name="Animation"
                                           Fill="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                           RenderTransformOrigin="0.5,0.5">
                                    <Rectangle.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform />
                                        </TransformGroup>
                                    </Rectangle.RenderTransform>
                                </Rectangle>
                            </Grid>
                        </Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Determinate" />
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0.3" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.75" Value="0.4" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.3" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">
                                            <EasingPointKeyFrame KeyTime="0" Value="-0.5,0.5" />
                                            <EasingPointKeyFrame KeyTime="0:0:0.75" Value="0.5,0.5" />
                                            <EasingPointKeyFrame KeyTime="0:0:1.5" Value="1.5,0.5" />
                                        </PointAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter TargetName="TemplateRoot" Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="True">
                            <Setter TargetName="Indicator" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  圆形进度条  -->
    <Style x:Key="CircleProgressBar" TargetType="{x:Type ProgressBar}">
        <Setter Property="Background" Value="{DynamicResource BorderLight}" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="Height" Value="40" />
        <Setter Property="Width" Value="40" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ProgressBarHelper.IndeterminateValue" Value="30" />
        <Setter Property="bpa:ProgressBarHelper.Thickness" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid x:Name="TemplateRoot">
                        <Canvas>
                            <!--  背景圈  -->
                            <Path x:Name="Background"
                                  RenderTransformOrigin="0, 0"
                                  Stroke="{TemplateBinding Background}"
                                  StrokeThickness="{Binding Path=(bpa:ProgressBarHelper.Thickness), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathFigure>
                                            <PathFigure.StartPoint>
                                                <MultiBinding Converter="{StaticResource DoublesToPointConverter}">
                                                    <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                             Path="ActualWidth"
                                                             RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    <Binding Source="0" />
                                                </MultiBinding>
                                            </PathFigure.StartPoint>
                                            <ArcSegment IsLargeArc="True" SweepDirection="Clockwise">
                                                <ArcSegment.Size>
                                                    <MultiBinding Converter="{StaticResource DoublesToSizeConverter}">
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Size>
                                                <ArcSegment.Point>
                                                    <MultiBinding Converter="{StaticResource GetArcPointConverter}">
                                                        <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Minimum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="ActualWidth" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Point>
                                            </ArcSegment>
                                        </PathFigure>
                                    </PathGeometry>
                                </Path.Data>
                            </Path>

                            <!--  进度圈  -->
                            <Path x:Name="Indicator"
                                  RenderTransformOrigin="0, 0"
                                  Stroke="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                  StrokeThickness="{Binding Path=(bpa:ProgressBarHelper.Thickness), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathFigure>
                                            <PathFigure.StartPoint>
                                                <MultiBinding Converter="{StaticResource DoublesToPointConverter}">
                                                    <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                             Path="ActualWidth"
                                                             RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    <Binding Source="0" />
                                                </MultiBinding>
                                            </PathFigure.StartPoint>
                                            <ArcSegment SweepDirection="Clockwise">
                                                <ArcSegment.IsLargeArc>
                                                    <MultiBinding Converter="{StaticResource IsLargeArcConverter}">
                                                        <Binding Path="Value" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Minimum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.IsLargeArc>
                                                <ArcSegment.Size>
                                                    <MultiBinding Converter="{StaticResource DoublesToSizeConverter}">
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Size>
                                                <ArcSegment.Point>
                                                    <MultiBinding Converter="{StaticResource GetArcPointConverter}">
                                                        <Binding Path="Value" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Minimum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="ActualWidth" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Point>
                                            </ArcSegment>
                                        </PathFigure>
                                    </PathGeometry>
                                </Path.Data>
                            </Path>

                            <!--  不确定进度  -->
                            <Path x:Name="IndeterminateBar"
                                  Stroke="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                  StrokeThickness="{Binding Path=(bpa:ProgressBarHelper.Thickness), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                  Visibility="Collapsed">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathFigure>
                                            <PathFigure.StartPoint>
                                                <MultiBinding Converter="{StaticResource DoublesToPointConverter}">
                                                    <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                             Path="ActualWidth"
                                                             RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    <Binding Source="0" />
                                                </MultiBinding>
                                            </PathFigure.StartPoint>
                                            <ArcSegment SweepDirection="Clockwise">
                                                <ArcSegment.Size>
                                                    <MultiBinding Converter="{StaticResource DoublesToSizeConverter}">
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Converter="{StaticResource HalfOfDoubleConverter}"
                                                                 Path="ActualWidth"
                                                                 RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Size>
                                                <ArcSegment.Point>
                                                    <MultiBinding Converter="{StaticResource GetArcPointConverter}">
                                                        <Binding Path="(bpa:ProgressBarHelper.IndeterminateValue)" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Minimum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="Maximum" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                        <Binding Path="ActualWidth" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                                                    </MultiBinding>
                                                </ArcSegment.Point>
                                            </ArcSegment>
                                        </PathFigure>
                                    </PathGeometry>
                                </Path.Data>
                                <Path.RenderTransform>
                                    <RotateTransform x:Name="Transform" CenterX="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ActualWidth, Converter={StaticResource HalfOfDoubleConverter}}" CenterY="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ActualWidth, Converter={StaticResource HalfOfDoubleConverter}}" />
                                </Path.RenderTransform>
                            </Path>
                        </Canvas>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="{TemplateBinding FontSize}"
                                   Visibility="{Binding Path=(bpa:ProgressBarHelper.ShowPercent), RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BooleanToVisibleConverter}}">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource GetPercentConverter}">
                                    <Binding Path="Value" RelativeSource="{RelativeSource AncestorType=ProgressBar}" />
                                    <Binding Path="Minimum" RelativeSource="{RelativeSource AncestorType=ProgressBar}" />
                                    <Binding Path="Maximum" RelativeSource="{RelativeSource AncestorType=ProgressBar}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Determinate" />
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard RepeatBehavior="Forever"
                                                TargetProperty="Angle"
                                                TargetName="Transform">
                                        <DoubleAnimation To="359" Duration="0:0:0.8" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsIndeterminate" Value="true">
                            <Setter TargetName="IndeterminateBar" Property="Visibility" Value="Visible" />
                            <Setter TargetName="Indicator" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>