|
|
@@ -30,7 +30,7 @@ namespace FryPot_DosingSystem.View |
|
|
|
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
AnimationByPath(qc_1); |
|
|
|
AnimationByPath(yunshuche,qc_1); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
@@ -40,30 +40,28 @@ namespace FryPot_DosingSystem.View |
|
|
|
/// <param name="path">路径</param> |
|
|
|
/// <param name="target">动画对象</param> |
|
|
|
/// <param name="duration">时间</param> |
|
|
|
private void AnimationByPath(Path path, int duration = 5) |
|
|
|
private void AnimationByPath(TextBox target, Path path, int duration = 5) |
|
|
|
{ |
|
|
|
//从XAML代码中获取移动路径数据 |
|
|
|
PathGeometry pg = PathGeometry.CreateFromGeometry(Geometry.Parse(path.Data.ToString())); |
|
|
|
//创建动画 |
|
|
|
DoubleAnimationUsingPath dapX = new DoubleAnimationUsingPath(); |
|
|
|
dapX.PathGeometry = pg; |
|
|
|
dapX.Source = PathAnimationSource.X; |
|
|
|
dapX.Duration = new Duration(TimeSpan.FromSeconds(duration)); |
|
|
|
target.RenderTransformOrigin = new Point(0.5, 0.5); |
|
|
|
|
|
|
|
DoubleAnimationUsingPath dapY = new DoubleAnimationUsingPath(); |
|
|
|
dapY.PathGeometry = pg; |
|
|
|
dapY.Source = PathAnimationSource.Y; |
|
|
|
dapY.Duration = new Duration(TimeSpan.FromSeconds(duration)); |
|
|
|
MatrixTransform matrix = new MatrixTransform(); |
|
|
|
TransformGroup groups = new TransformGroup(); |
|
|
|
groups.Children.Add(matrix); |
|
|
|
target.RenderTransform = groups; |
|
|
|
string registname = "matrix" + Guid.NewGuid().ToString().Replace("-", ""); |
|
|
|
this.RegisterName(registname, matrix); |
|
|
|
MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); |
|
|
|
matrixAnimation.PathGeometry = PathGeometry.CreateFromGeometry(Geometry.Parse(path.Data.ToString())); |
|
|
|
matrixAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); |
|
|
|
matrixAnimation.DoesRotateWithTangent = true;//跟随路径旋转 |
|
|
|
matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;//循环 |
|
|
|
Storyboard story = new Storyboard(); |
|
|
|
story.Children.Add(matrixAnimation); |
|
|
|
Storyboard.SetTargetName(matrixAnimation, registname); |
|
|
|
Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty)); |
|
|
|
|
|
|
|
//执行动画 |
|
|
|
this.tt.BeginAnimation(TranslateTransform.XProperty, dapX); |
|
|
|
this.tt.BeginAnimation(TranslateTransform.XProperty, dapY); |
|
|
|
|
|
|
|
//自动返回、永远循序 |
|
|
|
dapX.AutoReverse = true; |
|
|
|
dapX.RepeatBehavior = RepeatBehavior.Forever; |
|
|
|
dapY.AutoReverse = true; |
|
|
|
dapY.RepeatBehavior = RepeatBehavior.Forever; |
|
|
|
story.FillBehavior = FillBehavior.Stop; |
|
|
|
story.Begin(target, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |