| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1674 人关注过本帖
标题:WPF使用storyboard播放图像并能鼠标拖动问题
只看楼主 加入收藏
勤奋的小蚂蚁
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-11-18
结帖率:0
收藏
 问题点数:0 回复次数:1 
WPF使用storyboard播放图像并能鼠标拖动问题
求助:使用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);
搜索更多相关主题的帖子: 图像 new 播放 拖动 鼠标 
2021-01-20 15:46
勤奋的小蚂蚁
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-11-18
收藏
得分:0 
目前能拖动了,只是拖动的时候会越过wrappanel边界。
2021-01-27 16:59
快速回复:WPF使用storyboard播放图像并能鼠标拖动问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014627 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved