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. lms微服务的rpc通信框架

    RPC的概念 RPC 全称 Remote Procedure Call--远程过程调用.是为了解决远程调用服务的一种技术,使得调用者像调用本地服务一样方便透明.简单的说,RPC就是从一台机器(客户端) ...

  2. java:编写jar包加密工具,防止反编译

    懒人方案 网盘: 链接:https://pan.baidu.com/s/1x4OB1IF2HZGgtLhd1Kr_AQ提取码:glx7 网盘内是已生成可用工具,下载可以直接使用,使用前看一下READ. ...

  3. Nginx:Nginx配置文件详解

    Nginx是一款面向性能设计的HTTP服务器,相较于Apache.lighttpd具有占有内存少,稳定性高等优势. 如下是Nginx的配置详解: ######Nginx配置文件nginx.conf中文 ...

  4. Spring中的<context:annotation-config/>配置

    当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredA ...

  5. Java8 Map中新增的方法使用总结

    前言 得益于 Java 8 的 default 方法特性,Java 8 对 Map 增加了不少实用的默认方法,像 getOrDefault, forEach, replace, replaceAll, ...

  6. bash的RANDOM变量生成的是真正的随机数吗

    static void seedrand () { struct timeval tv; gettimeofday (&tv, NULL); sbrand (tv.tv_sec ^ tv.tv ...

  7. 剖析虚幻渲染体系(06)- UE5特辑Part 2(Lumen和其它)

    目录 6.5 Lumen 6.5.1 Lumen技术特性 6.5.1.1 表面缓存(Surface Cache) 6.5.1.2 屏幕追踪(Screen Tracing) 6.5.1.3 Lumen光 ...

  8. Spring Boot中的那些生命周期和其中的可扩展点(转)

    前言可扩展点的种类Spring Boot启动过程 1.SpringApplication的启动过程 2.ApplicationContext的启动过程 3.一般的非懒加载单例Bean在Spring B ...

  9. ELK多索引配置(filebeat)

     nginx日志收集: ​ ​ #-------------------------输入 filebeat.inputs: ​ #----------json日志---------- ​ - type ...

  10. 【有奖互动】HMS Core. Sparkle游戏应用创新沙龙,诚邀您参与

    活动简介 随着互联网基础设施的完善和"宅经济"效应凸显,游戏行业逆势上扬,迎来巨大消费市场.同时,用户需求愈加多样化,如何进一步创新和技术升级.提升核心竞争力已成为游戏开发与运营的 ...