fyf преди 2 години
родител
ревизия
b627b10557
променени са 2 файла, в които са добавени 25 реда и са изтрити 30 реда
  1. +5
    -8
      FryPot_DosingSystem/View/AgvView.xaml
  2. +20
    -22
      FryPot_DosingSystem/View/AgvView.xaml.cs

+ 5
- 8
FryPot_DosingSystem/View/AgvView.xaml Целия файл

@@ -313,14 +313,11 @@
<!--#endregion-->

<!--#region 运动轨迹路线-->
<Grid>
<TextBox x:Name="yunshuche" Style="{StaticResource 运输车}" IsEnabled="True" Text="No" Tag="Start" Margin="0,295,180,0" VerticalAlignment="Top" HorizontalAlignment="Right" >
<TextBox.RenderTransform>
<TranslateTransform x:Name="tt" X="0" Y="0"/>
</TextBox.RenderTransform>
</TextBox>
<Path x:Name="qc_1" Data="M1016.5,258.5 L978,258.5 978,340 337.32051,340 337.32051,218.75617" Fill="Transparent" HorizontalAlignment="Left" Height="122" Margin="329,218,150,0" Stroke="Red" Stretch="Fill" VerticalAlignment="Top"/>
</Grid>
<Canvas x:Name="cvsMain">
<TextBox x:Name="yunshuche" Style="{StaticResource 运输车}" IsEnabled="True" Text="No" Tag="Start" HorizontalAlignment="Right" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5"/>

<Path x:Name="qc_1" Data="M1016.5,258.5 L978,258.5 978,340 337.32051,340 337.32051,218.75617" Fill="Transparent" HorizontalAlignment="Right" Height="122" Margin="329,218,100,0" Stroke="Red" Stretch="Fill" VerticalAlignment="Top"/>
</Canvas>

<!--#endregion-->



+ 20
- 22
FryPot_DosingSystem/View/AgvView.xaml.cs Целия файл

@@ -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);
}
}
}

Зареждане…
Отказ
Запис