2012-06-29 3 views
15

에서 다음 코드는 실버 라이트에서 잘 작동 :WinRT가/메트로 애니메이션 코드 숨김

가 하나의 작은 변화를 필요로 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(); 
} 

가 컴파일 할 :

Storyboard.SetTargetProperty(doubleAnimation, "Width"); 

을하지만 때를 그것을 실행, 아무 일도 일어나지 않습니다.

속성을 "너비"에서 "불투명도"(변경 가능 : 0 및 종료 = 1)로 변경하면 작동합니다.

"너비"의 문제점은 무엇입니까?

+0

왜이 코드를 xaml로 옮기려면 http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx의 'EventTrigger'를 사용하지 않았습니까? – 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");