StackPanel位置

时间:2010-05-24 17:05:12

标签: silverlight silverlight-4.0

如何在动画后找到StackPanel的位置?

我有一个按钮,可以将堆叠面板向左滑动。但如果我想让它再次向左滑动,动画就不起作用。

1 个答案:

答案 0 :(得分: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();
    }