CS代码


新增
GridLengthAnimation继承自AnimationTimeline
public class GridLengthAnimation : AnimationTimeline
{
public static readonly DependencyProperty FromProperty;
public static readonly DependencyProperty ToProperty;
public static readonly DependencyProperty EasingFunctionProperty; static GridLengthAnimation()
{
FromProperty = DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));
ToProperty = DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));
EasingFunctionProperty = DependencyProperty.Register("EasingFunction", typeof(IEasingFunction), typeof(GridLengthAnimation));
} protected override Freezable CreateInstanceCore()
{
return new GridLengthAnimation();
} public override Type TargetPropertyType
{
get { return typeof(GridLength); }
} public IEasingFunction EasingFunction
{
get
{
return (IEasingFunction)GetValue(GridLengthAnimation.EasingFunctionProperty);
}
set
{
SetValue(GridLengthAnimation.EasingFunctionProperty, value);
} } public GridLength From
{
get
{
return (GridLength)GetValue(GridLengthAnimation.FromProperty);
}
set
{
SetValue(GridLengthAnimation.FromProperty, value);
}
} public GridLength To
{
get
{
return (GridLength)GetValue(GridLengthAnimation.ToProperty);
}
set
{
SetValue(GridLengthAnimation.ToProperty, value);
}
} public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
{
double fromValue = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
double toValue = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value; IEasingFunction easingFunction = this.EasingFunction; double progress = (easingFunction != null) ? easingFunction.Ease(animationClock.CurrentProgress.Value) : animationClock.CurrentProgress.Value; if (fromValue > toValue)
{
return new GridLength((1 - progress) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
}
else
{
return new GridLength((progress) * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
}
}
}

  

XAML代码

            <RowDefinition Height="40"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="grid" Width="0.06*"></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
</Grid.ColumnDefinitions>

  

调用代码如下

方法1

GridLengthAnimation d = new GridLengthAnimation();
d.From = new GridLength(0.06, GridUnitType.Star);
d.To = new GridLength(0.2, GridUnitType.Star);
d.Duration = TimeSpan.FromSeconds(0.2);
grid.BeginAnimation(ColumnDefinition.WidthProperty, d);

方法2

Xaml

   <Storyboard x:Key="showColumn" Duration="0:0:1" Storyboard.TargetName="grid" Storyboard.TargetProperty="Width" Completed="Storyboard_Completed">
<local:GridLengthAnimation From="0" To="300">
<local:GridLengthAnimation.EasingFunction>
<BounceEase EasingMode="EaseOut"/>
</local:GridLengthAnimation.EasingFunction>
</local:GridLengthAnimation>
</Storyboard>
<Storyboard x:Key="hideColumn" Duration="0:0:1" Storyboard.TargetName="grid" Storyboard.TargetProperty="Width" Completed="Storyboard_Completed">
<local:GridLengthAnimation From="300" To="0">
<local:GridLengthAnimation.EasingFunction>
<BounceEase EasingMode="EaseOut"/>
</local:GridLengthAnimation.EasingFunction>
</local:GridLengthAnimation>
</Storyboard>

CS

  BeginStoryboard((grid.Width.Value == 300) ? FindResource("hideColumn") as Storyboard : FindResource("showColumn") as Storyboard);

效果

Grid布局如何设置动画效果的更多相关文章

  1. VUE - 路由跳转时设置动画效果

    /* 为对应的路由跳转时设置动画效果 */   <transition name="fade">         <router-view />     & ...

  2. 有关ViewFlipper的使用及设置动画效果的讲解

    说到左右滑动,其实实现左右滑动的方式很多,有ViewPaer,自定义实现Viewgroup,gallery等都可以达到这种效果.这里做下ViewFliper实现左右滑动的效果. 会用到以下的技术: 1 ...

  3. Android 为PopupWindow设置动画效果

    首先定义显示效果的动画文件: <?xml version="1.0" encoding="utf-8"?> <set xmlns:androi ...

  4. Animator 设置动画效果

    1. 调节预设对象大小适中 2. 设置骨骼,修改关节 3. 拖入预设动作效果对象中 4. 将预设对象拉入场景中,并新建AnimatorController 5. 新建动作或BlendTree,设置参数 ...

  5. PopupWindow设置动画效果

    创建popupwindow的方法 Button menu; private void showPopupWindow() { //设置contentView float density = Densi ...

  6. 一起学android之设置ListView数据显示的动画效果(24)

    效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpX3FpbmdfeHVfa29uZw==/font/5a6L5L2T/fontsize/40 ...

  7. CSS3 动画效果带来的bug

    css3 动画效果比如transition:all 2s linear;这种用来计算及时的物体坐标的话会带来一定的问题 比如把一个DIV从A点移动到B点.JS为DIV.style.left=B; 但是 ...

  8. iOS开发笔记7:Text、UI交互细节、两个动画效果等

    Text主要总结UILabel.UITextField.UITextView.UIMenuController以及UIWebView/WKWebView相关的一些问题. UI细节主要总结界面交互开发中 ...

  9. ListView中内容的动画效果

    LayoutAnimationController用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果,可以在XML文件中设置,亦可以在Java代码中设置. 一种直接在 ...

随机推荐

  1. webpack(2)webpack核心概念

    前言   本质上,webpack 是一个用于现代 JavaScript 应用程序的 静态模块打包工具.当 webpack 处理应用程序时,它会在内部构建一个 依赖图(dependency graph) ...

  2. Linux:修改Ubuntu环境变量后bash找不到

    1.问题显示 修改环境变量,导致命令全部失效  2.解决办法 #使用备份bin export PATH=/usr/bin:/bin  之后使用命令就可以了. 3.找到修改的环境变量 一般修改的环境变量 ...

  3. MySQL索引类型总结和使用技巧以及注意事项 (转)

      在数据库表中,对字段建立索引可以大大提高查询速度.假如我们创建了一个 mytable表:  代码如下: CREATE TABLE mytable(   ID INT NOT NULL,    us ...

  4. XCTF getit

    一.查壳 是linux的文件.没加壳 二.拖入ida 分析一下逻辑,发现就是t的值就是flag. 写个exp就出来了. 三.exp分享 s='c61b68366edeb7bdce3c6820314b7 ...

  5. Outlook配置163邮箱

    一.在163邮箱设置处设置POP3/SMTP/IMAP 二.开启客户端授权码 三.打开Outlook,选择手动设置 选择POP/IMAP 密码是上文中的授权码 点击其它设置,勾选以下选项 点击完成即可

  6. Requests方法 -- post

    >>> import requests  导入requests库 >>> help(requests)  #查看requests方法Help on package ...

  7. 04 AOF日志:宕机了,Redis如何避免数据丢失

    接下来两篇将记录Redis持久化存储两大技术:AOF日志.RDB快照 本篇重点 "AOF日志实现""AOF日志三种写回策略""AOF重写--避免日志过 ...

  8. mybatis的增删改查返回值小析(六)

    本文验证了通过mybatis访问数据库时的,增删改查的返回值情况. 直接看代码. 1.service层 /** *@Author: Administrator on 2020/3/12 15:15 * ...

  9. shell脚本(11)-流程控制case

    一.case介绍 生产环境下,遇到要根据不同的状况执行不同的预案的情况,首先根据可能出现的情况写出对应预案,根据出现的情况来加载不同的预案 特点:根据给予的不同的代码块 二.case语法 case 变 ...

  10. 数据分析学习1-----matplotlib

    安装:Anaconda 详细见:https://blog.csdn.net/lwplwf/article/details/79162470 使用^ThinkPad-E560:~# spyder  命令 ...