WPF image控件移动 大家好,新手问题,希望帮忙看看:我在窗口中添了一个Image控件,我想让它在窗口中,不停的左右移动。我在for循环里把它的margin属性不停的增减,结果程序会出现未响应的状态,等到循环完了一下子就跳到了最后的位置。请问如何解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不能像你这么做,你应该使用RenderTransform和动画来进行处理,上Google和百度搜一下,网上很多解决方案 我用StoryBoard可以实现动画效果了,但是我想让动画只播放一次,怎么转换为C#代码? Storyboard story = new Storyboard(); story.AutoReverse = true; story.RepeatBehavior = RepeatBehavior.Forever; //我想让它只播放一次,怎么改? story.Children.Add(xAnimation); 参考RepeatBehavior设置 <!-- 创建一个无限循环的周期为2秒的动画. --> <DoubleAnimation Storyboard.TargetName="ForeverRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="Forever" /> <!-- 创建一个周期为2秒的动画,该动画4秒钟重复一次. --> <DoubleAnimation Storyboard.TargetName="FourSecondsRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:4" /> <!-- 创建一个周期为2秒的动画,重复执行2次. --> <DoubleAnimation Storyboard.TargetName="TwiceRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="2x" /> <!-- 创建一个周期为2秒的动画,仅执行一半,也就是执行1秒钟,To 150 --> <DoubleAnimation Storyboard.TargetName="HalfRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0.5x" /> <!-- Create an animation that repeats for one second. The resulting animation plays for one second, half of its Duration. It animates from 50 to 150. --> <DoubleAnimation Storyboard.TargetName="OneSecondRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:1" /> 这段代码如果改成C#的代码,应该怎么写? DoubleAnimation xAnimation = new DoubleAnimation(); xAnimation.Duration = new Duration(TimeSpan.FromSeconds(60));//这里我怎么改为让它重复2次? xAnimation.RepeatBehavior = new System.Windows.Media.Animation.RepeatBehavior(2); 已解决了,xAnimation.RepeatBehavior = new RepeatBehavior(1);谢谢大家! 正则提取网页指定标签内容 如何设置右键菜单 问个SQL分页问题,关于max字段有重复值问题 C# HashTable(急用) 鼠标在DataGridView上移动时,如何判断当前点所在的列式哪一列 求助高手:如何设置AxWebbrowser的选中元素? 从ASP.NET转向做WinForm开发,需要注意些什么呢? 请问如何利用C#更改文件夹名称? 如何实现进程注入后访问组件对象的方法 为了不让<<Visual C#.Net 核心网络核心编程>> 误导大家对异步Socket编程的理解,我将我得源代码贴出,大家请帮测试.(1) 语音系统问题 字符串截取问题
story.AutoReverse = true;
story.RepeatBehavior = RepeatBehavior.Forever; //我想让它只播放一次,怎么改?
story.Children.Add(xAnimation);
<!-- 创建一个无限循环的周期为2秒的动画. -->
<DoubleAnimation
Storyboard.TargetName="ForeverRepeatingRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="Forever" /> <!-- 创建一个周期为2秒的动画,该动画4秒钟重复一次. -->
<DoubleAnimation
Storyboard.TargetName="FourSecondsRepeatingRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:4" /> <!-- 创建一个周期为2秒的动画,重复执行2次. -->
<DoubleAnimation
Storyboard.TargetName="TwiceRepeatingRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="2x" /> <!-- 创建一个周期为2秒的动画,仅执行一半,也就是执行1秒钟,To 150 -->
<DoubleAnimation
Storyboard.TargetName="HalfRepeatingRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="0.5x" /> <!-- Create an animation that repeats for one second. The resulting animation
plays for one second, half of its Duration. It animates from 50 to 150. -->
<DoubleAnimation
Storyboard.TargetName="OneSecondRepeatingRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:1" />
DoubleAnimation xAnimation = new DoubleAnimation();
xAnimation.Duration = new Duration(TimeSpan.FromSeconds(60));//这里我怎么改为让它重复2次?
xAnimation.RepeatBehavior = new System.Windows.Media.Animation.RepeatBehavior(2);
xAnimation.RepeatBehavior = new RepeatBehavior(1);谢谢大家!