原文:WPF实现左右移动(晃动)动画效果

实现控件或布局的左右移动(晃动)主要用到DoubleAnimation以及Storyboard

布局代码为:

<Canvas>
<Grid Width="200" Height="100" Background="MediumAquamarine" Name="GroupboxArea" Canvas.Left="100" Canvas.Top="200"/>
<Button Content="Button" Height="25" Width="78" Click="Button_Click"/>
</Canvas>

后台代码为:

 private void Button_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation DAnimation = new DoubleAnimation();
DAnimation.From = 100;//起点
DAnimation.To = 280;//终点
DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//时间 Storyboard.SetTarget(DAnimation, GroupboxArea);
Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
Storyboard story = new Storyboard(); story.Completed += new EventHandler(story_Completed);//完成后要做的事
//story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上
story.Children.Add(DAnimation);
story.Begin();
}
void story_Completed(object sender, EventArgs e)
{
DoubleAnimation DAnimation = new DoubleAnimation();
DAnimation.From = 280;//起点
DAnimation.To = 100;//终点
DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//时间 Storyboard.SetTarget(DAnimation, GroupboxArea);
Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
Storyboard story = new Storyboard(); story.Completed += new EventHandler(storyCompleted);//完成后要做的事
//story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上
story.Children.Add(DAnimation);
story.Begin();
} void storyCompleted(object sender, EventArgs e)
{
DoubleAnimation DAnimation = new DoubleAnimation();
DAnimation.From = 100;//起点
DAnimation.To = 200;//终点
DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//时间 Storyboard.SetTarget(DAnimation, GroupboxArea);
Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
Storyboard story = new Storyboard(); //story.Completed += new EventHandler(storyCompleted);//完成后要做的事
//story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上
story.Children.Add(DAnimation);
story.Begin();
}

WPF实现左右移动(晃动)动画效果的更多相关文章

  1. WPF编游戏系列 之七 动画效果(2)

    原文:WPF编游戏系列 之七 动画效果(2)        上一篇已经对关闭窗口图标进行了动画效果处理,本篇将对窗口界面的显示和关闭效果进行处理.由于所有的动画效果都是针对窗口界面的Canvas,所以 ...

  2. WPF编游戏系列 之六 动画效果(1)

    原文:WPF编游戏系列 之六 动画效果(1)        本篇主要针对界面进行动画效果处理.首先在打开或关闭界面时,使其产生动态效果而不是生硬的显示或消失(如下图).其次在鼠标放到关闭窗口图标上时, ...

  3. WPF实现3D翻转的动画效果

    1.前端代码实现 1.1 原理见代码注析 <Grid MouseDown="Grid_MouseDown"> <Viewport3D> <Viewpo ...

  4. WPF 分享一种背景动画效果

    今天看微软的一个Samples,发现一个蛮好玩的背景样式,如下图所示: 风格比较卡哇伊. <Window x:Class="WPFSamplesTest.MainWindow" ...

  5. 动画(Animation) 之 (闪烁、左右摇摆、上下晃动等效果)

    左右晃动的效果: (这边显示没那么流畅) 一.续播  (不知道取什么名字好,就是先播放动画A, 接着播放动画B) 有两种方式. 第一种,分别动画两个动画,A和B, 然后先播放动画A,设置A 的 Ani ...

  6. wpf image控件循环显示图片 以达到动画效果 问题及解决方案

    1>最初方案: 用wpf的image控件循环显示图片,达到动画效果,其实就是在后台代码动态改变Image.Source的值,关键代码: ; i < ; i++)//六百张图片 { Bitm ...

  7. 【WPF】两则动画效果

    原文:[WPF]两则动画效果 引言 利用WPF的动画可以轻而易举的实现各种各样的特效,如擦除,滑动进入等,先看两个效果图 第一个效果 这个动画其实利用了OpacityMask和LinearGradie ...

  8. WPF 有趣的动画效果

    WPF 有趣的动画效果         这一次我要呈上一个简单的文章,关于给你的WPF apps加入美丽的光线动画,可是我对动画这东西可能有点入迷了.         实际上.我对动画如此的入迷,以至 ...

  9. WPF 画线动画效果实现

    原文:WPF 画线动画效果实现 弄了将近三天才搞定的,真是艰辛的实现. 看了很多博客,都太高深了,而且想要实现的功能都太强大了,结果基础部分一直实现不了,郁闷啊~ 千辛万苦终于找到了一个Demo,打开 ...

随机推荐

  1. Linux中U盘和SD卡加载卸载命令

    U盘挂载命令U盘插入的时候会显示启动信息,启动信息中sda: sda1指U盘的设备名为sda1dev设备目录下有一个sda1设备文件,此设备文件就是我们插入的U盘,我们将这个设备文件挂载到Linux系 ...

  2. 数据类型总结——Number(数值类型)

    相关文章 简书原文:https://www.jianshu.com/p/9fb573ef10da 数据类型总结——概述:https://www.cnblogs.com/shcrk/p/9266015. ...

  3. 【topcoder SRM 702 DIV 2 250】TestTaking

    Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...

  4. Android 在Service里面启动Activity

    直接在代码: Intent dialogIntent = new Intent(getBaseContext(), YourActivity.class); dialogIntent.addFlags ...

  5. php 模拟post的新发现,重点在最后的新方法

    最近两天项目需要,由于服务器正在开发,客户端进度稍快一些,没有服务器进行联调.因此我重操旧业,用PHP快速的写了一些web页面,算是当测试桩程序了,七八个web接口,基本上5到6个小时搞定了.由于当前 ...

  6. ArcGIS Runtime支持的GP工具列表(转 )

    转自原文 ArcGIS Runtime支持的GP工具列表(转 ) 目前ArcGIS Runtime有两个版本 Basic 版本和Standard版本,而Basic版本不支持Geoprocessing( ...

  7. c# 调用ArcEngine的GP工具

    转自原文c# 调用ArcEngine的GP工具,AE调用GP工具 IAoInitialize m_AoInitialize = new AoInitializeClass(); esriLicense ...

  8. cocos2d-x win8下的环境配置和建立项目

    cocos2dx 跨平台.可是看网上说开发最合适还是在vs2010中,基本是编完后再移植到安卓. 1.去官网下载源代码2.2.3版本号的. 2.然后运行根文件夹下的build-win32.bat(须要 ...

  9. [tmux] Automate your workflow using tmux scripts

    Do you have a standard workflow that involves setting up a specific tmux layout, or running certain ...

  10. win7注册表常用设置

    win7注册表常用设置 一.总结 一句话总结:regedit可以修改很多东西,电脑时间,背景,u盘读写,鼠标右键情况. 二.win7注册表常用设置 一. 秀出自我风格的屏幕保护画面 1.气泡屏幕保护 ...