zoukankan      html  css  js  c++  java
  • 用后台代码创建Storyboard

                string storyboardName = "MyStoryBoard";
                
    string myXamlElement = "MyXamlElement";
                
    int newLeftPosition = 120;
                Storyboard sb 
    = XamlReader.Load(String.Format(
                
    @"<Storyboard xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" x:Name=""{0}"">
                    <DoubleAnimation Storyboard.TargetName=""{1}""
                    Storyboard.TargetProperty=""(Canvas.Left)""
                    To=""{2}"" Duration=""00:00:00.1200000""/>
                    </Storyboard>
    ", storyboardName, myXamlElement, newLeftPosition)) as Storyboard;
                
    //Add a delegate to remove the storyboard from resources as soon as it is finished. 
                sb.Completed += new EventHandler(sb_Completed);
                
    //Add to the resources of the page 
                this.Resources.Add(sb);
                
    //Begin the storyboard which will animate the element to the correct position. 
                sb.Begin();

    在不少的应用中需要动态的创建动画作出一些复杂的效果。比如说当当拖拽元素是可以简单的用c#代码创建一个storyboard并在这个board中创建一个DoubleAnimation。但是用c#代码创建动画会导致runtime errors因为这还是silverlight的一个bug。但是用 xaml 并load他成为一个简单的storyboard。
    xamlReader 对象有一个非常有用的Load()方法。
    这里要提醒一点  创建Storyboard一定要把属性些完整了。 不要漏写了类似x:Name这样的属性。 若够漏写silverlight不会报任何错误。在调试时是直接跳出。
    我就犯了这样的错误 
  • 相关阅读:
    vue中插槽的理解
    父子组件的通信
    vue3.0怎么禁用eslint校验代码和修改端口号
    三大排序
    让机器人实现自主行走 没你想的那么难
    国内外知名激光雷达公司盘点
    激光雷达寿命短,思岚通过什么技术来解决?
    浅谈SLAM的回环检测技术
    除了ROS, 机器人定位导航还有其他方案吗?
    思岚科技即将登陆“2018日本机器人周”精彩抢先看
  • 原文地址:https://www.cnblogs.com/nasa/p/1072371.html
Copyright © 2011-2022 走看看