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 anima开发者_Go百科tion does not work.
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();
}
精彩评论