Il seguente codice funziona bene in Silverlight:WinRT/Metro Animazione in code-behind
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 ha bisogno di una piccola modifica per rendere più compilare:
Storyboard.SetTargetProperty(doubleAnimation, "Width");
ma quando si eseguilo, non succede niente.
Se si modifica la proprietà da "Larghezza" a "Opacità" (modificare anche Da = 0 e A = 1) che funziona.
Qual è il problema con "Larghezza"?
Perché non hai usato il 'EventTrigger' http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx per spostare tutto questo codice su xaml? – RredCat
@RredCat: per quanto ne so, non abbiamo EventTrigger in WinRT. –