2012-03-26 2 views
2

typ가 정수이기 때문에 이중 애니메이션이 작동하지 않습니다. Integeranimation 클래스가 있습니까? 아니면 다른 방식으로하고 있습니다. 저는 정적 애니메이션에는 관심이 없지만 이벤트 기반 (바람직하게는 프로그래밍 방식) 애니메이션에 관심이 있습니다.Silverlight에서 zIndex 속성에 애니메이션을 적용하는 방법은 무엇입니까?

public static void Swap(UIElement ui1, UIElement ui2, double seconds) 
     { 
      var z2 = (int)ui1.GetValue(Canvas.ZIndexProperty); 
      var z3 = (int)ui2.GetValue(Canvas.ZIndexProperty); 
      DoubleAnimation da1 = new DoubleAnimation(); 
      DoubleAnimation da2 = new DoubleAnimation(); 
      Duration d = new Duration(TimeSpan.FromSeconds(seconds)); 
      da1.Duration = d; 
      da2.Duration = d; 
      Storyboard sb = new Storyboard(); 
      Storyboard.SetTarget(da1, ui1); 
      Storyboard.SetTarget(da2, ui2); 
      Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.ZIndex)")); 
      Storyboard.SetTargetProperty(da2, new PropertyPath("(Canvas.ZIndex)")); 
      sb.Duration = d; 
      sb.Children.Add(da1); 
      sb.Children.Add(da2); 
      da1.To = (double)z3; 
      da2.To = (double)z2; 
      sb.Begin(); 



     } 

     private void Btn1_Click_1(object sender, RoutedEventArgs e) 
     { 
      var z2 = (int)Image2.GetValue(Canvas.ZIndexProperty); 
      var z3 = (int)Image3.GetValue(Canvas.ZIndexProperty); 

      Swap(Image2, Image3, 3); 

     } 
+0

그러나 기본 요소를 옮기고 동시에 zindex 속성을 전환했다면? 그럼 나는 그것을 움직일 수 있었다! – marko

답변

1

당신은 int 속성에 애니메이션 수 없습니다. 그것이 실제로 의미하는 바를 생각해보십시오.

시각적으로 가까울수록 불투명도가 생기게됩니다. 그리고 애니메이션 완료 이벤트에서 Zindex를 변경하십시오.

3

DiscreteObjectKeyFrame을 사용하여 ObjectAnimationUsingKeyFrames를 사용하여 신중한 값에 애니메이션을 적용 할 수 있습니다.

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.ZIndex)" Storyboard.TargetName="MyObject"> 
    <DiscreteObjectKeyFrame KeyTime="0" Value="250"/> 
</ObjectAnimationUsingKeyFrames> 

또는 코드로 입력 할 수 있습니다.

+0

작동하지 않습니다! –

관련 문제