C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace AnimationTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DoubleAnimation a = new DoubleAnimation();//定义
a.RepeatBehavior = new RepeatBehavior();//重复次数,延迟不重复
//a.RepeatBehavior = new RepeatBehavior(TimeSpan.Parse("0:0:15"));//整个动画持续时间,中途停止动画
//a.RepeatBehavior = RepeatBehavior.Forever;//无限重复
a.BeginTime=TimeSpan.Parse("0:0:1");//延迟开始时间
//a.SpeedRatio = 2;//动画速度快2倍,影响TimeSpan.Parse
//a.AccelerationRatio = 0.33;//加速阶段从时间百分比0%到33%
//a.DecelerationRatio = 0.33;//减速阶段从时间百分比100%-33%到100%;
//a.IsCumulative = true;//仅与RepeatBehavior一起使用在a.By下50-150-50跳150-200-150
//a.IsAdditive = true;//获取属性默认值,从默认值开始动画
//a.FillBehavior = FillBehavior.Stop;//动画完之后恢复原始值
//a.From = 50;//起始,若默认值不是50则跳到50在进行动画
a.AutoReverse = true;//往返
//a.To = 100;
a.By = ;//等于a.To = 100 + a.Form;
a.Duration = new Duration(TimeSpan.Parse("0:0:5"));//花费时间
b.BeginAnimation(Button.WidthProperty,a);//调用开始
}
}
}

XMAL

<Window x:Class="AnimationTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Window.Resources>
<Style x:Key="bt1" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Width">
<DoubleAnimation To="" Duration="0:0:5" AutoReverse="True" IsAdditive="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Canvas Margin="12,12,359,187">
<Button x:Name="b" Width="">
CS
</Button>
<Button Canvas.Top="" Width="" Style="{StaticResource ResourceKey=bt1}">
XAML
</Button>
<Button Canvas.Top="">
Color
<Button.Background>
<LinearGradientBrush>
<GradientStop Color="Blue" Offset=""/>
<GradientStop Color="Black" Offset="0.5"/>
<GradientStop Color="Blue" Offset=""/>
</LinearGradientBrush>
</Button.Background>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard >
<ColorAnimation From="Black" To="White" Duration="0:0:2" AutoReverse="True"
Storyboard.TargetProperty="Background.GradientStops[1].Color"
RepeatBehavior="Forever"/>
<DoubleAnimation From="" To="" Duration="0:0:2" AutoReverse="True"
Storyboard.TargetProperty="Background.GradientStops[1].Offset"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
<Button Canvas.Top="" Canvas.Left="">
Color
<Button.Background>
<LinearGradientBrush>
<GradientStop Color="Blue" Offset=""/>
<GradientStop Color="White" Offset="0.5"/>
<GradientStop Color="Blue" Offset=""/>
</LinearGradientBrush>
</Button.Background>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="" To="" Duration="0:0:2" AutoReverse="True"
Storyboard.TargetProperty="Background.GradientStops[1].Offset"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
</Canvas>
<Canvas Margin="161,12,114,174">
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard TargetName="p2" TargetProperty="Opacity">
<DoubleAnimation From="" To="" AutoReverse="True" RepeatBehavior="Forever" Duration="0:0:5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<Image Name="p1" Source="/AnimationTest;component/Images/p1.bmp" />
<Image Name="p2" Source="/AnimationTest;component/Images/p2.bmp" />
</Canvas>
<Canvas Margin="400,12,12,264" Background="Black" TextBlock.Foreground="White" TextBlock.FontSize="">
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard TargetProperty="Opacity" RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="title1" BeginTime="0:0:2"
From="" To="" Duration="0:0:2" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="title2" BeginTime="0:0:6"
From="" To="" Duration="0:0:2" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="title3" BeginTime="0:0:10"
From="" To="" Duration="0:0:2" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="title4" BeginTime="0:0:14"
From="" To="" Duration="0:0:2" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="title5" BeginTime="0:0:18"
From="" To="" Duration="0:0:2" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="" Name="title1">title1</TextBlock>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="" Name="title2">title2</TextBlock>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="" Name="title3">title3</TextBlock>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="" Name="title4">title4</TextBlock>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="" Name="title5">title5</TextBlock>
</Canvas>
<Canvas Margin="0,144,12,89" Background="Black">
<Image Source="/AnimationTest;component/Images/1.bmp" Height="" Width="">
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)"
From="" To="" Duration="0:0:9" RepeatBehavior="Forever" AutoReverse="True"/>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Top)"
Duration="0:0:9" RepeatBehavior="Forever" AutoReverse="True">
<LinearDoubleKeyFrame Value="" KeyTime="0:0:0"/>
<LinearDoubleKeyFrame Value="" KeyTime="0:0:1"/>
<LinearDoubleKeyFrame Value="" KeyTime="0:0:2"/>
<LinearDoubleKeyFrame Value="" KeyTime="0:0:3"/>
<SplineDoubleKeyFrame Value="" KeySpline="0,1 1,0" KeyTime="0:0:4"/>
<SplineDoubleKeyFrame Value="" KeySpline="0,1 1,0" KeyTime="0:0:5"/>
<SplineDoubleKeyFrame Value="" KeySpline="0,1 1,0" KeyTime="0:0:6"/>
<DiscreteDoubleKeyFrame Value="" KeyTime="0:0:7"/>
<DiscreteDoubleKeyFrame Value="" KeyTime="0:0:8"/>
<DiscreteDoubleKeyFrame Value="" KeyTime="0:0:9"/>
<!--KeyTime省略则匀速动画,也可以用百分比设值、Paced速率-->
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>
</Canvas>
<Canvas Margin="400,67,66,223" Background="Black" TextBlock.Foreground="White">
<TextBlock Width="" Height="" Text="play">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="Text" Duration="0:0:5" RepeatBehavior="Forever" AutoReverse="True">
<DiscreteStringKeyFrame Value="play"/>
<DiscreteStringKeyFrame Value="Play"/>
<DiscreteStringKeyFrame Value="PLay"/>
<DiscreteStringKeyFrame Value="PLAy"/>
<DiscreteStringKeyFrame Value="PLAY"/>
<DiscreteStringKeyFrame Value="PLAY"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</Canvas>
</Grid>
</Window>

源自《WPF 揭秘》一书

WPF 各种基础动画实现的更多相关文章

  1. WPF 画线动画效果实现

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

  2. iOS开发UI篇—核心动画(基础动画)

    转自:http://www.cnblogs.com/wendingding/p/3801157.html 文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(基础动画) iOS ...

  3. WPF中的动画——(三)时间线(TimeLine)

    WPF中的动画——(三)时间线(TimeLine) 时间线(TimeLine)表示时间段. 它提供的属性可以让控制该时间段的长度.开始时间.重复次数.该时间段内时间进度的快慢等等.在WPF中内置了如下 ...

  4. HT for Web基础动画介绍

    在上一篇<基于HT for Web矢量实现3D叶轮旋转>一文中,我略微提了下HT for Web基础动画的相关用法,但是讲得不深入,今天就来和大家分享下HT for Web基础动画的相关介 ...

  5. 核心动画基础动画(CABasicAnimation)关键帧动画

    1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...

  6. WPF编程学习——动画

    前言 使用动画,是增强用户体验的一种有效的手段.合理的动画,可以让应用程序的界面看起来更加自然.真实.流畅.舒适,更有效地向用户展现信息,用户也更容易接受.同时也增加了软件使用的乐趣,提高用户粘度.( ...

  7. Core Animation中的基础动画

    基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...

  8. jQuery里面的常用的事件和基础动画的实现

    一:了解jquery里面常用的事件 二:了解基础动画的实现 1:加载DOM 在JavaScript中使用window.onload事件作为窗体加载事件(它在页面所有数据加载完成之后才会执行) 在jQu ...

  9. Core Animation 动画的使用:关键帧动画、基础动画、动画组

    首先让我们了解下什么是 Core Animation,Core Animation 为核心动画,他为图形渲染和动画提供了基础.使用核心动画,我们只需要设置起点.终点.关键帧等一些参数,剩下的工作核心动 ...

随机推荐

  1. Lucene.Net 2.3.1开发介绍 —— 四、搜索(三)

    原文:Lucene.Net 2.3.1开发介绍 -- 四.搜索(三) Lucene有表达式就有运算符,而运算符使用起来确实很方便,但另外一个问题来了. 代码 4.3.4.1 Analyzer anal ...

  2. form表单多值提交

    $.ajax({ cache: true, type: "POST", url:ajaxCallUrl, data:$('#yourformid').serialize(),// ...

  3. jdom dom4j解析xml不对dtd doctype进行验证(转)

    一.写在所有之前:因为dom4j和jdom在这个问题上处理的方法是一模一样的,只是一个是SAXBuilder 一个SAXReader,这里以jdom距离,至于dom4j只需要同理替换一下就可以了.二. ...

  4. expect实现ssh自动登录

    expect实现ssh自动登录   #!/usr/local/bin/expect set PASSWD [lindex $argv 1] set IP [lindex $argv 0] set CM ...

  5. rzsz不能大于4G,securefx传5.2G没有问题,

    rzsz不能大于4G,securefx传5.2G没有问题, 查看系统限制: $ulimit -acore file size          (blocks, -c) 0data seg size  ...

  6. 关于使用commons-email包测试发送邮件遇到的问题

    项目中有个需求是这样的:客户办理某一项业务,当用户成功提交业务办理信息后,系统生成一个业务随机码给用户,以此作为以后的业务办理结果查询依据.鉴于随机码较长,方便用户记录,在生成随机码的同时,提供用户发 ...

  7. 搭建php环境时解决jpeg6 make: ./libtool:命令未找到

    搭建php环境时解决jpeg6 make: ./libtool:命令未找到 [root@bogon jpeg-6b]# make; make install ./libtool --mode=comp ...

  8. 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)——初识WiX

    原文:使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)--初识WiX Visual Studio 打包安装七宗罪 开发.NET的人,肯定会使用Visual ...

  9. .Net路(十三)导出数据库到EXCEL

    .NET出口Office文件(word,excel)有两种方法我明白.一个存储在导出的文件中server录以下.利用response输出到浏览器地址栏,直接打开:还有直接利用javascript来导出 ...

  10. Coreseek:indexer crashed神秘

    浩哥前两天让我再Coreseek该指数再次这样做,由于需求方面变化不大,公司名称应出现指数.在添加的配置文件的面孔sql_field_string:串场.. 此属性特别有用,因为它不仅作为过滤器的特性 ...