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);

效果

最新文章

  1. 快钱支付与Sql Server的乐观锁和悲观锁
  2. sublime几个有用的快捷键
  3. shadow fight 1.6.0 内购
  4. [转]Java汉字按照拼音排序
  5. 使用Angular CLI进行单元测试和E2E测试
  6. 搭建centos7的开发环境1-系统安装及Python配置
  7. 《利用Python进行数据分析&#183;第2版》
  8. Python游戏编程入门2
  9. SVM:随机产生100个点,建立模型,找出超平面方程——Jaosn niu
  10. 最小生成树算法(krustra+prime)
  11. 13条Android手机必备技巧 让玩机更有趣
  12. 自学如何去学习jQuery
  13. 串口流控制详解(CTS/RTS,DTR/DSR)
  14. Check failed: mdb_status == 0 (2 vs. 0) No such file or directory
  15. Azure Blob数据迁移工具
  16. 2018年最新 Java面试通关要点汇总集
  17. JAVA中简单的MD5加密类(MD5Utils)
  18. os,操作文件和目录
  19. Windows10 IIS安装php manager和IIS URL Rewrite 2.0组件的方法
  20. JS高级 1

热门文章

  1. 升级Ubuntu 16.04 到 Ubuntu 18.04 的方法
  2. Docker:Docker部署postgresql数据库
  3. bugku秋名山车神
  4. 剑指offer 37-42
  5. 打开设置windows10内置linux功能-启用linux子系统
  6. 个人博客开发之blog-api项目统一结果集api封装
  7. HCNA Routing&amp;Switching之动态路由协议OSPF基础(一)
  8. VS Code 下载安装并设置中文面板显示
  9. 【LeetCode】933.最近的请求次数
  10. 自动化测试(1)selenium+python+chrome 连接测试