更新: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. POJ 分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  2. Python 读写文件中w与wt, r与rt的区别

    w和wt是一们的,r和rt是一样的,t是默认参数,可以省略的,help(open)就能看到open的参数的详细说明. w,r,wt,rt都是python里面文件操作的模式.w是写模式,r是读模式.t是 ...

  3. Hive配置文件中配置项的含义详解(收藏版)

    这里面列出了hive几乎所有的配置项,下面问题只是说出了几种配置项目的作用.更多内容,可以查看内容 问题导读: 1.hive输出格式的配置项是哪个? 2.hive被各种语言调用如何配置? 3.hive ...

  4. thinkphp标签实现bootsrtap轮播carousel实例

    thinkphp标签实现bootsrtap轮播carousel实例由于轮播carousel第一个div需要设置active样式才能正常显示,上面的圆点也同样需要数字,使用volist标签在循环的同时可 ...

  5. java多线程----JUC集合”01之 框架

    java集合的架构.主体内容包括Collection集合和Map类:而Collection集合又可以划分为List(队列)和Set(集合). 1. List的实现类主要有: LinkedList, A ...

  6. Python入门之面向对象的__init__和__new__方法

    Python入门之面向对象的__init__和__new__方法

  7. 20145106 java 实验四

    这次的实验是Android开发实验基础.Android开发是一个很大的工程,但是这次只是一个小小的入门. 首先将SDK文件复制到-根目录下,之后将Android Studio复制到电脑里. 并指明SD ...

  8. 20145333茹翔 Exp8 Web基础

    20145333茹翔 Exp8 Web基础 实验问题回答 (1)什么是表单 表单是一个包含表单元素的区域,表单元素是允许用户在表单中(比如:文本域.下拉列表.单选框.复选框等等)输入信息的元素,表单在 ...

  9. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  10. windows下如何获取系统已存在的盘符 【c++】

    #include <iostream> #include "classAh.h" #include <atlstr.h> using namespace s ...