wpf storyboard stop

clike 复制代码
Storyboard BeginStory = (Storyboard)this.FindResource("StarAnimation");
BeginStory.Begin(this,true);
.
.
.
BeginStory.Stop(this);

真麻烦 参数的问题

iscontrolable 中的true少不了 this也少不了,this是做动画的uielement

动画的属性传递信息

clike 复制代码
doubleAnimation = new DoubleAnimation(line1.Y1, line1.Y2, new System.Windows.Duration(TimeSpan.FromSeconds(secs)))
            {
                AccelerationRatio = 0,
                BeginTime = TimeSpan.FromSeconds(bsecs),
            };
            doubleAnimation.Completed += (sender, e) => { //do complete thing  };
            //这样简单点 但是不知道怎么控制 line1.BeginAnimation(Line.Y1Property, doubleAnimation);
            StoryboardLine1 = new Storyboard();
            //Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(Line.Y1Property));
            Storyboard.SetTarget(doubleAnimation, this.line1);
            StoryboardLine1.Children.Add(doubleAnimation);
            

以下转载:https://blog.csdn.net/xwlyun/article/details/9156897

在wpf中我们常用storyboard故事板装载很多的动画处理Animation,我们需要用Storyboard.SetTarget设置操作的对象,需要用Storyboard.SetTargetProperty设置操作对象的操作属性PropertyPath,本例将说明一种操作属性PropertyPath的便利方法:

效果:点击button,button的横坐标x由12到300,播放过程动画

clike 复制代码
			 this.button1.RenderTransform = new TranslateTransform();

            Storyboard sb = new Storyboard();
            DoubleAnimation da = new DoubleAnimation();
            da.From = 12;
            da.To = 300;
            da.Duration = TimeSpan.FromSeconds(3);
            sb.Children.Add(da);

            DependencyProperty[] propertyChain = new DependencyProperty[]
            {
                Button.RenderTransformProperty,
                TranslateTransform.XProperty
            };

            Storyboard.SetTarget(da, this.button1);
            Storyboard.SetTargetProperty(da, new PropertyPath("(0).(1)", propertyChain));

            sb.Completed += new EventHandler((object sender1, EventArgs e1) => { MessageBox.Show("completed"); });
            sb.Begin();

一般我们在写到Storyboard.SetTargetProperty时遇到new PropertyPath,

如果是简单的属性,例如Button.WidthProperty,我们可以直接new PropertyPath(Button.WidthProperty)达到目的,

但如果你发现你需要操作到的属性无法在Button中直接'.'出来,就需要用到上例用到的属性链方法:

首先定义一个属性链:

复制代码
        DependencyProperty[] propertyChain = new DependencyProperty[]
        {
            Button.RenderTransformProperty,
            TranslateTransform.XProperty
        };

属性链的写法,定义一个DependencyProperty属性的数组,该数组中的元素均是Property属性,且按照从属关系先后排列,例如上例中,我们需要先将button的RenderTransform设置为TranslateTransform,然后通过TranslateTransform的XProperty来更改button的x坐标,

当然,别忘了初始化button的RenderTransform属性= new TranslateTransform(),否则动画将没有效果。

相关推荐
Chris _data4 天前
WPF 学习第三天 — Modbus RTU 串口通信
hadoop·学习·wpf
布吉岛的石头5 天前
Java 程序员第 43 阶段05:微服务整合大模型,跨服务调用架构设计实战,Seata分布式事务实战
wpf
步步为营DotNet5 天前
基于.NET Aspire 实现云原生应用的高效监控与可观测性
云原生·.net·wpf
芒鸽5 天前
HarmonyOS 分布式开发实战:设备协同、数据共享与跨设备迁移
分布式·wpf·harmonyos
Volunteer Technology5 天前
Flink状态管理与容错(二)
大数据·flink·wpf
happyprince6 天前
07_verl-Trainer模块详解
人工智能·架构·wpf·强化学习
bugcome_com6 天前
WPF + Prism 技术指南与实战项目(二、模板搭建)
wpf
小满Autumn7 天前
log4net 日志框架 — 从配置到实战速查手册
笔记·c#·.net·wpf·上位机·log4net
政沅同学7 天前
基于 C# WPF + HALCON 的工业视觉算法工具框架(开源)
开发语言·c#·wpf
happyprince7 天前
03_verl-设计理念与核心原理
wpf