2012-06-29 39 views
15

aşağıdaki kod Silverlight çalışıyor:WinRT/Metro Animasyon kod arkasında

o tek küçük bir değişiklik ihtiyacı WinRT/Metro'da
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(); 
} 

derlemek yapmak:

Storyboard.SetTargetProperty(doubleAnimation, "Width"); 

ama sizi Koş, hiçbir şey olmuyor.

Özelliği "Genişlik" ten "Opaklık" a (aynı zamanda Kimden = 0 ve Git = 1) değiştirirseniz, bu işlev çalışır.

"Genişlik" ile ilgili sorun nedir?

+0

Tüm bu kodu xaml'e taşımak için niçin 'EventTrigger' http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx'i kullanmadınız? – RredCat

+2

@RredCat - Bildiğim kadarıyla WinRT'de EventTrigger yok. –

cevap

20

aşağıdaki eklemek için: Sorunu gidermek gibi görünüyor

doubleAnimation.EnableDependentAnimation = true; 

.

+0

Teşekkürler, çok fazla saç çekmeden sonra! – legends2k

+2

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj819807#dependent nedenini açıklar – legends2k

+0

Çok yardımcı, teşekkürler! –

1

emin değilim ama kullanmayı deneyin:

Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty); 

yerine İhtiyacınız

Storyboard.SetTargetProperty(doubleAnimation, "Width"); 
İlgili konular