The following code works fine in Silverlight:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Storyboard storyboard = new Storyboard();
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 50;
doubleAnimation.To = 100;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.AutoReverse = true;
doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
storyboard.Children.Add(doubleAnimation);
Storyboard.SetTarget(doubleAnimation, button1);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));
storyboard.Begin();
}
In WinRT/Metro it needs one minor change to make it compile:
Storyboard.SetTargetProperty(doubleAnimation, "Width");
but when you run it, nothing happens.
If you change the property from "Width" to "Opacity" (also change From=0 and To=1) that works.
What is the problem with "Width"?
You need to add the following:
doubleAnimation.EnableDependentAnimation = true;
That seems to fix the problem.
I'm not sure but try to use:
Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty);
Instead of
Storyboard.SetTargetProperty(doubleAnimation, "Width");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With