From bebe9b8c61a3cadbfcbb90229d2f529ccd5f28a3 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Sun, 25 Apr 2021 23:27:19 +0800
Subject: [PATCH] fixed #766
---
.../Controls/Other/AnimationPath.cs | 71 ++++++-------------
1 file changed, 21 insertions(+), 50 deletions(-)
diff --git a/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs b/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs
index d55395d3..99123a99 100644
--- a/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs
@@ -12,19 +12,10 @@ namespace HandyControl.Controls
{
public class AnimationPath : Shape
{
- ///
- /// 故事板
- ///
private Storyboard _storyboard;
- ///
- /// 路径长度
- ///
private double _pathLength;
- ///
- /// 路径
- ///
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(nameof(Data),
typeof(Geometry), typeof(AnimationPath), new FrameworkPropertyMetadata(null,
OnPropertiesChanged));
@@ -37,9 +28,6 @@ namespace HandyControl.Controls
}
}
- ///
- /// 路径
- ///
public Geometry Data
{
get => (Geometry) GetValue(DataProperty);
@@ -48,31 +36,19 @@ namespace HandyControl.Controls
protected override Geometry DefiningGeometry => Data ?? Geometry.Empty;
- ///
- /// 路径长度
- ///
public static readonly DependencyProperty PathLengthProperty = DependencyProperty.Register(
"PathLength", typeof(double), typeof(AnimationPath), new FrameworkPropertyMetadata(ValueBoxes.Double0Box, OnPropertiesChanged));
- ///
- /// 路径长度
- ///
public double PathLength
{
get => (double) GetValue(PathLengthProperty);
set => SetValue(PathLengthProperty, value);
}
- ///
- /// 动画间隔时间
- ///
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
"Duration", typeof(Duration), typeof(AnimationPath), new FrameworkPropertyMetadata(new Duration(TimeSpan.FromSeconds(2)),
OnPropertiesChanged));
- ///
- /// 动画间隔时间
- ///
public Duration Duration
{
get => (Duration) GetValue(DurationProperty);
@@ -94,27 +70,31 @@ namespace HandyControl.Controls
}
}));
- ///
- /// 是否正在播放动画
- ///
public bool IsPlaying
{
get => (bool) GetValue(IsPlayingProperty);
set => SetValue(IsPlayingProperty, ValueBoxes.BooleanBox(value));
}
- public static readonly DependencyProperty RepeatBehaviorProperty = DependencyProperty.Register(
- "RepeatBehavior", typeof(RepeatBehavior), typeof(AnimationPath), new PropertyMetadata(RepeatBehavior.Forever));
+ public static readonly DependencyProperty RepeatBehaviorProperty =
+ Timeline.RepeatBehaviorProperty.AddOwner(typeof(AnimationPath),
+ new PropertyMetadata(RepeatBehavior.Forever));
- ///
- /// 动画重复行为
- ///
public RepeatBehavior RepeatBehavior
{
get => (RepeatBehavior) GetValue(RepeatBehaviorProperty);
set => SetValue(RepeatBehaviorProperty, value);
}
+ public static readonly DependencyProperty FillBehaviorProperty =
+ Timeline.FillBehaviorProperty.AddOwner(typeof(AnimationPath), new PropertyMetadata(FillBehavior.Stop));
+
+ public FillBehavior FillBehavior
+ {
+ get { return (FillBehavior) GetValue(FillBehaviorProperty); }
+ set { SetValue(FillBehaviorProperty, value); }
+ }
+
static AnimationPath()
{
StretchProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(Stretch.Uniform,
@@ -126,25 +106,16 @@ namespace HandyControl.Controls
public AnimationPath() => Loaded += (s, e) => UpdatePath();
- ///
- /// 动画完成事件
- ///
public static readonly RoutedEvent CompletedEvent =
EventManager.RegisterRoutedEvent("Completed", RoutingStrategy.Bubble,
typeof(EventHandler), typeof(AnimationPath));
- ///
- /// 动画完成事件
- ///
public event EventHandler Completed
{
add => AddHandler(CompletedEvent, value);
remove => RemoveHandler(CompletedEvent, value);
}
- ///
- /// 更新路径
- ///
private void UpdatePath()
{
if (!Duration.HasTimeSpan || !IsPlaying) return;
@@ -160,7 +131,6 @@ namespace HandyControl.Controls
_pathLength
});
- //定义动画
if (_storyboard != null)
{
_storyboard.Stop();
@@ -168,25 +138,26 @@ namespace HandyControl.Controls
}
_storyboard = new Storyboard
{
- RepeatBehavior = RepeatBehavior
+ RepeatBehavior = RepeatBehavior,
+ FillBehavior = FillBehavior
};
_storyboard.Completed += Storyboard_Completed;
var frames = new DoubleAnimationUsingKeyFrames();
- //开始位置
- var frame0 = new LinearDoubleKeyFrame
+
+ var frameIn = new LinearDoubleKeyFrame
{
Value = _pathLength,
KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero)
};
- //结束位置
- var frame1 = new LinearDoubleKeyFrame
+ frames.KeyFrames.Add(frameIn);
+
+ var frameOut = new LinearDoubleKeyFrame
{
- Value = -_pathLength,
+ Value = FillBehavior == FillBehavior.Stop ? - _pathLength : 0,
KeyTime = KeyTime.FromTimeSpan(Duration.TimeSpan)
};
- frames.KeyFrames.Add(frame0);
- frames.KeyFrames.Add(frame1);
+ frames.KeyFrames.Add(frameOut);
Storyboard.SetTarget(frames, this);
Storyboard.SetTargetProperty(frames, new PropertyPath(StrokeDashOffsetProperty));