#2
勤奋的小蚂蚁2021-01-27 16:59
|
求助:使用Storyboard创建多张图像连续从左到右播放的动画,现要求可以手动鼠标拖动某张图像,并能左右移动,该如何实现呢?
下面ss是一个wrappanel控件。目前已经实现了自动播放。
double totalWidth = 0;
double tt = ss.ActualWidth;
for (int i = 2; i < 8; i++)
{
BitmapImage biReserveImage = new BitmapImage();
biReserveImage.BeginInit();
biReserveImage.UriSource = new Uri(@"D:\scenery" + String.Format("{0:D1}", i) + ".jpg", UriKind.RelativeOrAbsolute);
biReserveImage.EndInit();
totalWidth += biReserveImage.Width;
Image ii = new Image();
ii.Source = biReserveImage;
ss.Children.Add(ii);
}
myStoryboard = new Storyboard();
ss.RenderTransform = new TranslateTransform();
DependencyProperty[] propertyChain = new DependencyProperty[]
{
Image.RenderTransformProperty,
TranslateTransform.XProperty
};
DoubleAnimation InDoubleAnimation = new DoubleAnimation();
InDoubleAnimation.From = 0;
InDoubleAnimation.To = -totalWidth + gg.ActualWidth;
InDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(20));
InDoubleAnimation.AccelerationRatio = 0.1;
InDoubleAnimation.DecelerationRatio = 0.5;
InDoubleAnimation.FillBehavior = FillBehavior.HoldEnd;
Storyboard.SetTargetName(InDoubleAnimation, "ss");
Storyboard.SetTargetProperty(InDoubleAnimation, new PropertyPath("(0).(1)", propertyChain));
myStoryboard.Children.Add(InDoubleAnimation);
//myStoryboard.Duration = new Duration(TimeSpan.FromSeconds(10));
myStoryboard.RepeatBehavior = RepeatBehavior.Forever;
myStoryboard.Begin(ss, true);