首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

WPF 一组图片循环挪动

2012-08-11 
WPF 一组图片循环移动要实现的是 一个视图里面有几张图片排列在一起,然后他们一起从屏幕左边往右边移动,当

WPF 一组图片循环移动
要实现的是 一个视图里面有几张图片排列在一起,然后他们一起从屏幕左边往右边移动,当此组图片显示完毕,然后接着又从头开始移动。如此反复,希望牛人指点。最好有例子。

[解决办法]
你可以移动Canvas 当从左边移动到右边的时候 你让他在返回左边继续做运动,这个需要用到动画
 Image img = new Image();

img = _obj as Image;

if (img.Opacity > 1)
{
img.Opacity = img.Opacity / 100;
}

double actime;
double delaytime;
if (ca.Time == "0")
{

}
if (!ca.IsTimer)
{
actime = 0.1;
}
else
{
if (double.Parse(ca.Time) == 0)
{
actime = 0.1;
}
else
{
actime = double.Parse(ca.Time);
}
}
Storyboard sb = new Storyboard();
// ImageDelBinding(img);
if (ca.IsWidth)
{
DoubleAnimation widthA = new DoubleAnimation(img.Width, double.Parse(ca.Width), new Duration(TimeSpan.FromSeconds(actime)));
Storyboard.SetTargetProperty(widthA, new PropertyPath(Image.WidthProperty));
sb.Children.Add(widthA);
}
if (ca.IsHeight)
{
DoubleAnimation heightA = new DoubleAnimation(img.Height, double.Parse(ca.Height), new Duration(TimeSpan.FromSeconds(actime)));
Storyboard.SetTargetProperty(heightA, new PropertyPath(Image.HeightProperty));
sb.Children.Add(heightA);
}
if (ca.IsX)
{
DoubleAnimation leftA = new DoubleAnimation(double.Parse(img.GetValue(Canvas.LeftProperty).ToString()), double.Parse(ca.X), new Duration(TimeSpan.FromSeconds(actime)));
Storyboard.SetTargetProperty(leftA, new PropertyPath(Canvas.LeftProperty));
sb.Children.Add(leftA);
}
if (ca.IsY)
{
DoubleAnimation topA = new DoubleAnimation(double.Parse(img.GetValue(Canvas.TopProperty).ToString()), double.Parse(ca.Y), new Duration(TimeSpan.FromSeconds(actime)));
Storyboard.SetTargetProperty(topA, new PropertyPath(Canvas.TopProperty));
sb.Children.Add(topA);
}
if (ca.IsAlpha)
{
double alpha_d;
if (double.Parse(ca.Alpha) > 1)
{
alpha_d = double.Parse(ca.Alpha) / 100;
}
else {
alpha_d = double.Parse(ca.Alpha) ;
}
DoubleAnimation oA = new DoubleAnimation(img.Opacity, alpha_d, new Duration(TimeSpan.FromSeconds(actime)));
Storyboard.SetTargetProperty(oA, new PropertyPath(Image.OpacityProperty));
sb.Children.Add(oA);
}

if (!ca.IsDelay)
{
delaytime = 0;
}
else
{
delaytime = double.Parse(ca.Delay);
}
// sb.FillBehavior = FillBehavior.Stop;
sb.Completed += new EventHandler(sb_Completed);
sb.BeginTime = TimeSpan.FromSeconds(delaytime);
sb.Begin(img);
大概的动画 可以这样来做 你看一下自己组织组织

热点排行