2012-06-29 11 views
15

निम्नलिखित कोड ठीक Silverlight में काम करता है:WinRT/मेट्रो एनीमेशन में कोड-पीछे

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(); 
} 

WinRT/मेट्रो में यह एक मामूली परिवर्तन की जरूरत है यह संकलन करने के लिए:

Storyboard.SetTargetProperty(doubleAnimation, "Width"); 

लेकिन जब आप इसे चलाओ, कुछ भी नहीं होता है।

आप "चौड़ाई" से संपत्ति को बदलते हैं "अस्पष्टता" (यह भी = 0 और करने के लिए = 1 से बदलने) के लिए है कि काम करता है।

"चौड़ाई" के साथ समस्या क्या है?

+0

क्यों आप 'EventTrigger' http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx XAML को यह सब कोड बढ़ने के लिए नहीं इस्तेमाल किया है? – RredCat

+2

@RredCat - जहां तक ​​मुझे पता है कि हमारे पास WinRT में EventTrigger नहीं है। –

उत्तर

20

आप की जरूरत है निम्नलिखित जोड़ने के लिए:

doubleAnimation.EnableDependentAnimation = true; 

समस्या को ठीक करने लगता है यही कारण है कि ।

+0

धन्यवाद आदमी, बहुत सारे बाल खींचने के बाद! – legends2k

+2

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj819807#dependent – legends2k

+0

कारण बताता है बहुत उपयोगी, धन्यवाद! –

1

मुझे यकीन है कि नहीं कर रहा हूँ, लेकिन इस्तेमाल करने की कोशिश:

Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty); 

बजाय

Storyboard.SetTargetProperty(doubleAnimation, "Width"); 
संबंधित मुद्दे