Üks asi, mida ma pidevalt dokumentatsioonist järgi vaatan on animatsioonide programne loomine, no ma ei tea, igakord on mingi näpukas sees.
Seega siin on kood lihtsa animatsiooni loomiseks:
private void Rectangle_MouseEnter(object sender, MouseEventArgs e) {
Rectangle animatedRect = sender as Rectangle;
Storyboard storyboard = new Storyboard();
DoubleAnimation widthAnimation = new DoubleAnimation();
DoubleAnimation heightAnimation = new DoubleAnimation();
// kaua animeerime
Duration duration = new Duration(TimeSpan.FromSeconds(1));
storyboard.Duration = duration;
widthAnimation.Duration = duration;
heightAnimation.Duration = duration;
// keda me animeerime
Storyboard.SetTarget(widthAnimation, animatedRect);
Storyboard.SetTarget(heightAnimation, animatedRect);
// kelle mida me animeerime
Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("(Width)"));
Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("(Height)"));
// kuidas animeerime
widthAnimation.To = animatedRect.ActualWidth * 2;
heightAnimation.To = animatedRect.ActualHeight * 2;
// animatsioonid ressursside sekka storyboard.Children.Add(widthAnimation);
storyboard.Children.Add(heightAnimation);
LayoutRoot.Resources.Add("unique_id", storyboard);
// saagu valgus storyboard.Begin();
}