add IsIndeterminate property for CircleProgressBar

This commit is contained in:
NaBian committed 2020-11-11 22:22:08 +08:00
1 parent d0a303e48b
commit 5e31009dcf
3 files changed
+86 -11

No files matched your search

@@ -14,6 +14,14 @@
<hc:CircleProgressBar Value="{Binding Value,ElementName=SliderDemo}" Margin="16,0,0,0" ShowText="False" Width="40" Height="40" ArcThickness="10" Style="{StaticResource ProgressBarWarningCircle}"/>
<hc:CircleProgressBar Value="{Binding Value,ElementName=SliderDemo}" Margin="16,0,0,0" Width="50" Height="50" Style="{StaticResource ProgressBarDangerCircle}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,32,0,0">
<hc:CircleProgressBar IsIndeterminate="True"/>
<hc:CircleProgressBar IsIndeterminate="True" Margin="16,0,0,0" Background="Transparent"/>
<hc:CircleProgressBar IsIndeterminate="True" Margin="16,0,0,0" Width="20" Height="20" ArcThickness="2" Style="{StaticResource ProgressBarSuccessCircle}"/>
<hc:CircleProgressBar IsIndeterminate="True" Margin="16,0,0,0" Width="30" Height="30" ArcThickness="6" Style="{StaticResource ProgressBarInfoCircle}"/>
<hc:CircleProgressBar IsIndeterminate="True" Margin="16,0,0,0" Width="40" Height="40" ArcThickness="10" Style="{StaticResource ProgressBarWarningCircle}"/>
<hc:CircleProgressBar IsIndeterminate="True" Margin="16,0,0,0" Width="50" Height="50" Style="{StaticResource ProgressBarDangerCircle}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,32,0,0">
<hc:WaveProgressBar Value="{Binding Value,ElementName=SliderDemo}"/>
<hc:WaveProgressBar Value="{Binding Value,ElementName=SliderDemo}" FontSize="20" Margin="16,0,0,0" WaveThickness="4" WaveStroke="#FFFF0080">
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using HandyControl.Data;
using HandyControl.Expression.Shapes;
@@ -19,6 +20,10 @@ namespace HandyControl.Controls
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(CircleProgressBar), new PropertyMetadata(default(string)));
public static readonly DependencyProperty IsIndeterminateProperty =
ProgressBar.IsIndeterminateProperty.AddOwner(typeof(CircleProgressBar),
new FrameworkPropertyMetadata(ValueBoxes.FalseBox));
private Arc _indicator;
static CircleProgressBar()
@@ -47,6 +52,12 @@ namespace HandyControl.Controls
set => SetValue(ArcThicknessProperty, value);
}
public bool IsIndeterminate
{
get => (bool)GetValue(IsIndeterminateProperty);
set => SetValue(IsIndeterminateProperty, value);
}
private void SetProgressBarIndicatorAngle()
{
if (_indicator == null) return;
@@ -134,6 +134,67 @@
</Setter>
</Style>
<ControlTemplate x:Key="CircleProgressBarIndeterminateTemplate" TargetType="hc:CircleProgressBar">
<ControlTemplate.Resources>
<Storyboard x:Key="IsIndeterminate" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="TemplateRoot">
<LinearDoubleKeyFrame KeyTime="0:0:1.568" Value="360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" Storyboard.TargetName="arc">
<SplineDoubleKeyFrame KeyTime="0" Value="0"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:0.666" Value="135"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:1.333" Value="270"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:1.999" Value="405"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:2.666" Value="540"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:3.333" Value="675"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:3.999" Value="810"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:4.666" Value="945"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:5.332" Value="1080"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(shapes:Arc.StartAngle)" Storyboard.TargetName="arc">
<SplineDoubleKeyFrame KeyTime="0" Value="-5"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:0.666" Value="-130"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:1.333" Value="-5"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(shapes:Arc.EndAngle)" Storyboard.TargetName="arc">
<SplineDoubleKeyFrame KeyTime="0" Value="5"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:0.666" Value="130"/>
<SplineDoubleKeyFrame KeySpline="0.4,0.0,0.2,1" KeyTime="0:0:1.333" Value="5"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<hc:SimplePanel x:Name="TemplateRoot" RenderTransformOrigin="0.5,0.5">
<hc:SimplePanel.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</hc:SimplePanel.RenderTransform>
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" EndAngle="360" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" StrokeThickness="0"/>
<shapes:Arc RenderTransformOrigin="0.5,0.5" StartAngle="-5" EndAngle="5" ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" Width="{TemplateBinding ActualWidth}" StrokeThickness="0" Height="{TemplateBinding ActualHeight}" x:Name="arc" Fill="{TemplateBinding Foreground}">
<shapes:Arc.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</shapes:Arc.RenderTransform>
</shapes:Arc>
</hc:SimplePanel>
<ControlTemplate.Triggers>
<Trigger Property="IsIndeterminate" Value="true">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource IsIndeterminate}"/>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="CircleProgressBarTemplate" TargetType="hc:CircleProgressBar">
<hc:SimplePanel x:Name="TemplateRoot">
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" EndAngle="360" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" StrokeThickness="0"/>
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" Width="{TemplateBinding ActualWidth}" StrokeThickness="0" Height="{TemplateBinding ActualHeight}" x:Name="PART_Indicator" Fill="{TemplateBinding Foreground}"/>
<TextBlock Visibility="{Binding ShowText,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Text}"/>
</hc:SimplePanel>
</ControlTemplate>
<Style x:Key="ProgressBarCircleBaseStyle" TargetType="hc:CircleProgressBar">
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
@@ -141,17 +202,12 @@
<Setter Property="Width" Value="100"/>
<Setter Property="ArcThickness" Value="4"/>
<Setter Property="Text" Value="{Binding Value,RelativeSource={RelativeSource Self},StringFormat={}{0:F0} %}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:CircleProgressBar">
<hc:SimplePanel x:Name="TemplateRoot">
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" EndAngle="360" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" StrokeThickness="0"/>
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" Width="{TemplateBinding ActualWidth}" StrokeThickness="0" Height="{TemplateBinding ActualHeight}" x:Name="PART_Indicator" Fill="{TemplateBinding Foreground}"/>
<TextBlock Visibility="{Binding ShowText,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Text}"/>
</hc:SimplePanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template" Value="{StaticResource CircleProgressBarTemplate}"/>
<Style.Triggers>
<Trigger Property="IsIndeterminate" Value="True">
<Setter Property="Template" Value="{StaticResource CircleProgressBarIndeterminateTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ProgressBarWaveBaseStyle" TargetType="hc:WaveProgressBar">