Here is my code which i think is correct. But it's not working. Is this some kind of bug or I did something wrong? Animating line segment from xaml works just fine.
MainWindow.xaml:
<Window x:Class="XXX.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Canvas Name="canvas">
</Canvas>
</Window>
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
anim();
}
void anim()
{
Path path = new Path { Stroke = Brushes.Red, StrokeThickness = 1 };
PathGeometry pg = new PathGeometry();
PathFigureCollection pfc = new PathFigureCollection();
PathFigure pf = new PathFigure { StartPoint = new Point(50, 50) };
Storyboard sb = new Storyboard
{
Duration = System.Windows.Duration.Forever,
BeginTime = new TimeSpan(0, 0, 0),
RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever,
Name = "sb"
};
LineSegment ls = new LineSegment
{
IsSmoothJoin = true,
Point = new Point(80, 50)
};
PointAnimation pa = new PointAnimation
{
BeginTime = new TimeSpan(0, 0, 0, 0, 0),
Duration = new Duration(new TimeSpan(0, 0, 0, 1)),
From = new Point(0, 0),
To = new Point(0, 100),
RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever,
AutoReverse = true,
};
Storyboard.SetTarget(pa, ls);
Storyboard.SetTargetProperty(pa, new PropertyPath("Point"));
sb.Children.Add(pa);
pf.Segments.Add(ls);
pfc.Add(pf);
pg.Figures = pfc;
path.Data = pg;
canvas.Children.Add(path);
sb.Begin();
}
}
For me it looks like sb.Begin(); doesn't fire or storyboard.settarget/setproperty is set incorrectly. But what's wrong if this is the case?