add WaveProgressBar

This commit is contained in:
NaBian committed 2019-03-07 23:37:34 +08:00
1 parent a2d947a389
commit 4c66d0dcf9
9 files changed
+203 -44

No files matched your search

+2 -2
View File
@@ -14,7 +14,7 @@ namespace HandyControl.Controls
{
if (d is UIElement element)
{
CreateTrriger(element, (string) e.NewValue);
CreateTrigger(element, (string) e.NewValue);
}
}
@@ -27,7 +27,7 @@ namespace HandyControl.Controls
private static CommandBinding GetCommandBinding(DependencyObject element)
=> (CommandBinding) element.GetValue(CommandBindingProperty);
private static void CreateTrriger(UIElement element, string link)
private static void CreateTrigger(UIElement element, string link)
{
element.CommandBindings.Remove(GetCommandBinding(element));
element.SetCurrentValue(CommandBindingProperty, DependencyProperty.UnsetValue);
@@ -2,19 +2,75 @@
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using HandyControl.Data;
using HandyControl.Expression.Drawing;
namespace HandyControl.Controls
{
/// <summary>
/// 波浪进度条
/// </summary>
[TemplatePart(Name = ElementWave, Type = typeof(FrameworkElement))]
[TemplatePart(Name = ElementClip, Type = typeof(FrameworkElement))]
public class WaveProgressBar : RangeBase
{
private const string ElementWave = "PART_Wave";
private const string ElementClip = "PART_Clip";
private FrameworkElement _waveElement;
private const double TranslateTransformMinY = -20;
private double _translateTransformYRange;
private TranslateTransform _translateTransform;
public WaveProgressBar() => Loaded += (s, e) => UpdateWave(Value);
static WaveProgressBar()
{
FocusableProperty.OverrideMetadata(typeof(CircleProgressBar),
FocusableProperty.OverrideMetadata(typeof(WaveProgressBar),
new FrameworkPropertyMetadata(ValueBoxes.FalseBox));
MaximumProperty.OverrideMetadata(typeof(CircleProgressBar),
MaximumProperty.OverrideMetadata(typeof(WaveProgressBar),
new FrameworkPropertyMetadata(ValueBoxes.Double100Box));
}
protected override void OnValueChanged(double oldValue, double newValue)
{
base.OnValueChanged(oldValue, newValue);
UpdateWave(newValue);
}
private void UpdateWave(double value)
{
if (_translateTransform == null || MathHelper.IsVerySmall(Maximum)) return;
var scale = 1 - value / Maximum;
var y = _translateTransformYRange * scale + TranslateTransformMinY;
_translateTransform.Y = y;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_waveElement = GetTemplateChild(ElementWave) as FrameworkElement;
var clipElement = GetTemplateChild(ElementClip) as FrameworkElement;
if (_waveElement != null && clipElement != null)
{
_translateTransform = new TranslateTransform
{
Y = clipElement.Height
};
_translateTransformYRange = clipElement.Height - TranslateTransformMinY;
_waveElement.RenderTransform = new TransformGroup
{
Children = {_translateTransform}
};
}
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(WaveProgressBar), new PropertyMetadata(default(string)));
@@ -33,22 +89,31 @@ namespace HandyControl.Controls
set => SetValue(ShowTextProperty, value);
}
public static readonly DependencyProperty WaveBrushProperty = DependencyProperty.Register(
"WaveBrush", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
public static readonly DependencyProperty WaveFillProperty = DependencyProperty.Register(
"WaveFill", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
public Brush WaveBrush
public Brush WaveFill
{
get => (Brush)GetValue(WaveBrushProperty);
set => SetValue(WaveBrushProperty, value);
get => (Brush) GetValue(WaveFillProperty);
set => SetValue(WaveFillProperty, value);
}
public static readonly DependencyProperty WaveDiameterProperty = DependencyProperty.Register(
"WaveDiameter", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(default(double)));
public static readonly DependencyProperty WaveThicknessProperty = DependencyProperty.Register(
"WaveThickness", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.Double0Box));
public double WaveDiameter
public double WaveThickness
{
get => (double)GetValue(WaveDiameterProperty);
set => SetValue(WaveDiameterProperty, value);
get => (double) GetValue(WaveThicknessProperty);
set => SetValue(WaveThicknessProperty, value);
}
public static readonly DependencyProperty WaveStrokeProperty = DependencyProperty.Register(
"WaveStroke", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
public Brush WaveStroke
{
get => (Brush) GetValue(WaveStrokeProperty);
set => SetValue(WaveStrokeProperty, value);
}
}
}
@@ -5,6 +5,7 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Converters.xaml"/>
<ResourceDictionary Source="../Border.xaml"/>
</ResourceDictionary.MergedDictionaries>
<LinearGradientBrush x:Key="ProgressBarIndicatorAnimatedFill" StartPoint="0,0" EndPoint="1,0">
@@ -70,13 +71,12 @@
</Style>
<Style x:Key="ProgressBarCircleBaseStyle" TargetType="controls:CircleProgressBar">
<Setter Property="controls:BorderElement.CornerRadius" Value="4"/>
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Width" Value="100"/>
<Setter Property="ArcThickness" Value="4"/>
<Setter Property="Text" Value="{Binding Value,RelativeSource={RelativeSource Self},StringFormat={}{0} %}"/>
<Setter Property="Text" Value="{Binding Value,RelativeSource={RelativeSource Self},StringFormat={}{0:F0} %}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:CircleProgressBar">
@@ -90,4 +90,57 @@
</Setter>
</Style>
<Style x:Key="ProgressBarWaveBaseStyle" TargetType="controls:WaveProgressBar">
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="Width" Value="100"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Text" Value="{Binding Value,RelativeSource={RelativeSource Self},StringFormat={}{0:F0} %}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:WaveProgressBar">
<ControlTemplate.Resources>
<Storyboard x:Key="StoryboardOnLoaded" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" Storyboard.TargetName="PART_Wave">
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-400"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<StackPanel>
<Border Style="{StaticResource BorderCircular}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
<Viewbox>
<Border x:Name="PART_Clip" Style="{StaticResource BorderClip}" CornerRadius="100" Width="200" Height="200">
<Path x:Name="PART_Wave" Stroke="{TemplateBinding WaveStroke}" StrokeThickness="{TemplateBinding WaveThickness}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="600" Height="250" Fill="{TemplateBinding WaveFill}" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" Margin="0,0,-400,-20">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="0,1">
<PathFigure.Segments>
<PolyBezierSegment Points="0.5,1 0.5,0 1,0"/>
<PolyBezierSegment Points="1.5,0 1.5,1 2,1"/>
<PolyBezierSegment Points="2.5,1 2.5,0 3,0"/>
<PolyLineSegment Points="3,0 3,10, 0,10 0,1"/>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Border>
</Viewbox>
</Border>
<TextBlock Margin="0,10,0,0" Visibility="{Binding ShowText,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Text}"/>
</StackPanel>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource StoryboardOnLoaded}"/>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -196,6 +196,26 @@
<Setter Property="Foreground" Value="{DynamicResource DangerBrush}"/>
</Style>
<Style BasedOn="{StaticResource ProgressBarWaveBaseStyle}" TargetType="controls:WaveProgressBar">
<Setter Property="WaveFill" Value="{DynamicResource DarkPrimaryBrush}"/>
</Style>
<Style x:Key="ProgressBarSuccessWave" BasedOn="{StaticResource ProgressBarWaveBaseStyle}" TargetType="controls:WaveProgressBar">
<Setter Property="WaveFill" Value="{DynamicResource DarkSuccessBrush}"/>
</Style>
<Style x:Key="ProgressBarInfoWave" BasedOn="{StaticResource ProgressBarWaveBaseStyle}" TargetType="controls:WaveProgressBar">
<Setter Property="WaveFill" Value="{DynamicResource DarkInfoBrush}"/>
</Style>
<Style x:Key="ProgressBarWarningWave" BasedOn="{StaticResource ProgressBarWaveBaseStyle}" TargetType="controls:WaveProgressBar">
<Setter Property="WaveFill" Value="{DynamicResource DarkWarningBrush}"/>
</Style>
<Style x:Key="ProgressBarDangerWave" BasedOn="{StaticResource ProgressBarWaveBaseStyle}" TargetType="controls:WaveProgressBar">
<Setter Property="WaveFill" Value="{DynamicResource DarkDangerBrush}"/>
</Style>
<Style x:Key="ProgressBarFlat" TargetType="ProgressBar">
<Setter Property="Height" Value="4"/>
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>