Подскажите, как изменить анимацию объекта(шарика) относительно изменяющийся траектории
Xaml:
<Window.Resources>
<PathGeometry x:Key="geometryPath">
<PathFigure IsClosed="False" StartPoint="730, 330">
<QuadraticBezierSegment
x:Name="myBezier"
Point1="{Binding Point1, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Point2="{Binding Point2, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</PathFigure>
</PathGeometry>
</Window.Resources>
<Grid>
<StackPanel Margin="5 0 5 5" VerticalAlignment="Bottom">
<Label>Выберите расстояние до цели: 30, 60, 90, 120</Label>
<Slider x:Name="sld" ValueChanged="Slider_ValueChanged" Maximum="120" Minimum="30" TickFrequency="30" TickPlacement="BottomRight" Ticks="30, 60, 90, 120"/>
</StackPanel>
<Image Name="imageWeapon" Source="C:\Users\User\Desktop\КПО. Курсовая работа\Артиллерия.png" Margin="730 315 5 40" Width="50"></Image>
<Canvas>
<Path Stroke="Black" Data="{StaticResource geometryPath}" Canvas.Top="5" Canvas.Left="5" />
<Image Name="imageBall" Source="C:\Users\User\Desktop\КПО. Курсовая работа\Ядро1.png" Width="20" Canvas.Top="330" Canvas.Left="730">
<Image.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="myAnimation">
<DoubleAnimationUsingPath x:Name="Animation_1" Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:2" RepeatBehavior="Forever" PathGeometry="{StaticResource geometryPath}" Source="Y" ></DoubleAnimationUsingPath>
<DoubleAnimationUsingPath x:Name="Animation_2" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:2" RepeatBehavior="Forever" PathGeometry="{StaticResource geometryPath}" Source="X" ></DoubleAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>
</Canvas>
</Grid>
C#:
namespace WpfApp1
{
class Main : INotifyPropertyChanged {
Point point1;
public Point Point1 {
get => point1;
set => Set(ref point1, value);
}
Point point2;
public Point Point2 {
get => point2;
set => Set(ref point2, value);
}
public Main(double Value)
{
if (Value >= 30 && Value < 60) {
Point1 = new Point(650, 43.75);
Point2 = new Point(540, 350);
}
if (Value >= 60 && Value < 90) {
Point1 = new Point(487.5, 87.5);
Point2 = new Point(360, 350);
}
if (Value >= 90 && Value < 120) {
Point1 = new Point(325, 175);
Point2 = new Point(180, 350);
}
if (Value == 120) {
Point1 = new Point(162.5, 262.5);
Point2 = new Point(0, 350);
}
}
protected void Set<T>(ref T field, T value, [CallerMemberName] string propertyName = "") {
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public partial class MainWindow : Window
{
public MainWindow() {
InitializeComponent();
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
DataContext = new Main(sld.Value);
}
}
}