views:

100

answers:

1

How can I find the position of a StackPanel after it has been animated?

I have a button which slides the stackpanel to the left. But if I want it to slide to the left again, the animation does not work.

A: 

Nevermind. I found out how to do this...

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