2010-05-24 50 views
0

如何在動畫之後找到StackPanel的位置?StackPanel位置

我有一個按鈕,可以將堆棧面板向左滑動。但是如果我想讓它再次向左滑動,則動畫不起作用。

回答

0

沒關係。我發現如何做到這一點...

 private Storyboard SlideEffect(UIElement controlToAnimate, double positionToMove) 
    { 
     //Get position of stackpanel 
     GeneralTransform gt = controlToAnimate.TransformToVisual(gridWrapper); 
     Point p = gt.Transform(new Point(0, 0)); 

     //add new storyboard and animation 
     Storyboard sb = new Storyboard(); 
     DoubleAnimation da = new DoubleAnimation(); 
     da.To = p.X + positionToMove; 
     Storyboard.SetTarget(da, controlToAnimate); 
     Storyboard.SetTargetProperty(da, new PropertyPath("(controlToAnimate.RenderTransform).(TransformTranslate.X)")); 
     sb.Children.Add(da); 
     return sb; 
    } 

    private void btnNext_Click(object sender, RoutedEventArgs e) 
    { 
     SlideEffect(spCarousel, -200).Begin(); 
    }