更新:2007 年 11 月

对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理。

命名空间:  System.Windows.Media.Animation
程序集:  PresentationCore (在 PresentationCore.dll 中)
用于 XAML 的 XMLNS: http://schemas.microsoft.com/winfx/xaml/presentation

参考:

http://social.msdn.microsoft.com/Forums/zh-HK/wpf/thread/7d856f82-d112-4a1c-a457-1aeb1abe861b

http://technet.microsoft.com/zh-cn/office/system.windows.uielement.visibility%28it-it,VS.95%29.aspx

XAML实现:

  1. <Border Height="100" Width="80" CornerRadius="11,11,11,11" Margin="5" BorderThickness="2" Background="Brown" IsEnabled="False" Name="Bord11">
  2. <Border.Triggers>
  3. <EventTrigger RoutedEvent="Border.Loaded" >
  4. <EventTrigger.Actions>
  5. <BeginStoryboard>
  6. <Storyboard>
  7. <ObjectAnimationUsingKeyFrames  Storyboard.TargetProperty="Visibility" Duration="0:0:4">
  8. <ObjectAnimationUsingKeyFrames.KeyFrames>
  9. <DiscreteObjectKeyFrame KeyTime="0:0:1" >
  10. <DiscreteObjectKeyFrame.Value>
  11. <Visibility>Visible</Visibility>
  12. </DiscreteObjectKeyFrame.Value>
  13. </DiscreteObjectKeyFrame>
  14. <DiscreteObjectKeyFrame KeyTime="0:0:2" >
  15. <DiscreteObjectKeyFrame.Value>
  16. <Visibility>Hidden</Visibility>
  17. </DiscreteObjectKeyFrame.Value>
  18. </DiscreteObjectKeyFrame>
  19. <DiscreteObjectKeyFrame KeyTime="0:0:3" >
  20. <DiscreteObjectKeyFrame.Value>
  21. <Visibility>Collapsed</Visibility>
  22. </DiscreteObjectKeyFrame.Value>
  23. </DiscreteObjectKeyFrame>
  24. </ObjectAnimationUsingKeyFrames.KeyFrames>
  25. </ObjectAnimationUsingKeyFrames>
  26. </Storyboard>
  27. </BeginStoryboard>
  28. </EventTrigger.Actions>
  29. </EventTrigger>
  30. </Border.Triggers>
  31. <Label Height="39" Name="label1" Width="62">ABCDEFGH</Label>
  32. </Border>

<Border Height="100" Width="80" CornerRadius="11,11,11,11" Margin="5" BorderThickness="2" Background="Brown" IsEnabled="False" Name="Bord11">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Duration="0:0:4">
<ObjectAnimationUsingKeyFrames.KeyFrames>
<DiscreteObjectKeyFrame KeyTime="0:0:1" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:2" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:3" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>

</ObjectAnimationUsingKeyFrames.KeyFrames>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Border.Triggers>
<Label Height="39" Name="label1" Width="62">ABCDEFGH</Label>
</Border>

后台实现:

  1. ObjectAnimationUsingKeyFrames animate = new ObjectAnimationUsingKeyFrames();
  2. animate.Duration = new TimeSpan(0,0,4);
  3. animate.RepeatBehavior = RepeatBehavior.Forever;
  4. DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 1));
  5. DiscreteObjectKeyFrame kf2 = new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 2));
  6. DiscreteObjectKeyFrame kf3 = new DiscreteObjectKeyFrame(Visibility.Collapsed, new TimeSpan(0, 0,3));
  7. animate.KeyFrames.Add(kf1);
  8. animate.KeyFrames.Add(kf2);
  9. animate.KeyFrames.Add(kf3);
  10. Bord11.BeginAnimation(Border.VisibilityProperty, animate);

ObjectAnimationUsingKeyFrames animate = new ObjectAnimationUsingKeyFrames();
animate.Duration = new TimeSpan(0,0,4);
animate.RepeatBehavior = RepeatBehavior.Forever;
DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 1));
DiscreteObjectKeyFrame kf2 = new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 2));
DiscreteObjectKeyFrame kf3 = new DiscreteObjectKeyFrame(Visibility.Collapsed, new TimeSpan(0, 0,3));
animate.KeyFrames.Add(kf1);
animate.KeyFrames.Add(kf2);
animate.KeyFrames.Add(kf3);
Bord11.BeginAnimation(Border.VisibilityProperty, animate);

分享到:

如何对Visibility属性进行动画(XMAL /CS)的更多相关文章

  1. 【UWP】对 Thickness 类型属性进行动画

    好几个月没写 blog 了,一个是在忙新版的碧影壁纸,另一方面是等(观望)周年更新的 api(不过现在还是比较失望,仍然没法支持矩形以外的 Clip).闲话少说,进入主题. 在 UWP 中,出于性能考 ...

  2. Android笔记——Android中visibility属性VISIBLE、INVISIBLE、GONE的区别

    在Android开发中,大部分控件都有visibility这个属性,其属性有3个分别为"visible "."invisible"."gone&quo ...

  3. Android,visibility属性

    Android,visibility属性 1) 可见(visible)XML文件:android:visibility="visible"Java代码:view.setVisibi ...

  4. 【转】Android中visibility属性VISIBLE、INVISIBLE、GONE的区别

    原文网址:http://blog.csdn.net/chindroid/article/details/8000713 在Android开发中,大部分控件都有visibility这个属性,其属性有3个 ...

  5. [CSS]visibility 属性

    定义和用法 visibility 属性规定元素是否可见. 提示:即使不可见的元素也会占据页面上的空间.请使用 "display" 属性来创建不占据页面空间的不可见元素. 说明 这个 ...

  6. 自定义 Layer 属性的动画

    默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAnimation 到 Layer(显式动画),亦或是为属性指定一个动作然后修改它(隐式动画).   但有时候 ...

  7. Silverlight代码编写对控件的PlaneProjection.RotationY属性控制动画

    Canvas c; void btnDraw_Click(object sender, RoutedEventArgs e) { Storyboard story = new Storyboard() ...

  8. 视图属性+对象动画组件ViewPropertyObjectAnimator

    视图属性+对象动画组件ViewPropertyObjectAnimator   ViewPropertyObjectAnmator组件是一款对象动画(ObjectAnimator)封装组件.它将视图属 ...

  9. CSS属性组-动画、转换、渐变

    一.动画 animation动画属性是一个简写属性,用于设置六个动画属性 aninmation-name动画名称,被调用 animation-duration完成动画需要的持续时间 animation ...

随机推荐

  1. MFC工具栏的创建、设计与使用实例

    本文通过实例说明MFC工具栏的创建.设计和使用方法,包括三个demo.       demo1:创建一个工具栏 C++代码 //摘抄自MSDN demo1 (创建一个工具栏) 1.Create a t ...

  2. Linux服务器---安装Tomcat

    安装Tomcat Tomcat作为web服务器实现了对servlet和jsp的支持,centos目前不支持yum方式安装.在使用Tomcat之前,确保你已经安装并配置好了jdk,而且jdk的版本要和t ...

  3. WebService(JAX-WS、XFire、Axis三种)获取客户端ip

    WebService(JAX-WS.XFire.Axis三种)获取客户端ip JAX-WS.XFire.Axis三种webservice的获取客户端IP的简单实现过程: 1,基于JDK6 jax-ws ...

  4. python脚本监控获取当前Linux操作系统[内存]/[cpu]/[硬盘]/[登录用户]

    此脚本应用在linux, 前提是需要有python和python的psutil模块 脚本 #!/usr/bin/env python # coding=utf-8 import sys import ...

  5. MIME协议(详解范例)

    转载一:http://blog.csdn.net/bripengandre/article/details/2192982 转载二:http://blog.csdn.net/flfna/article ...

  6. 如何解决Visual Studio2010 编译时提示系统找不到指定文件问题

    前一段时间,开始使用vs2010编写程序,可是在编译的时候总是报错,提示系统找不到指定文件,导致无法正常运行程序,花了好久时间终于找到原因解决,是因为常规的输出目录 要与链接的常规的输出文件要相对应. ...

  7. 【Coursera】Technology :Fifth Week(2)

    The Ethernet Story Bob Metcalfe Bob 参与了 Xerox 研究项目,着手解决建造一个处处连接个人计算机的架构.当时,他们刚刚完成了 Internet 的开端 -具有 ...

  8. DFS回溯-函数递归-xiaoz triangles

    题目:小z 的三角形 ★实验任务 三角形的第1 行有n 个由"+"和"-"组成的符号,以后每行符 号比上行少1 个,2 个同号下面是"+", ...

  9. 01_Flume基本架构及原理

    Flume消息收集系统,在整个系统架构中的位置 Flume概况1) Apache软件基金会的顶级项目2)存在两个大的版本:Flume 0.9.x(Flume-OG,original generatio ...

  10. Robot framework(RF)学习基础

    1.框架特点 2.安装 3.基本内容 RF框架是通用的测试框架,一直由诺西网络维护. 易于使用 采用表格法 可以使用关键字驱动,数据驱动和行为驱动开发完成.(keyword-driven,data-d ...