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不会报任何错误。在调试时是直接跳出。
    我就犯了这样的错误 
  • 相关阅读:
    linux系统中对SSD硬盘优化的方法
    正则
    自己写的博客上线啦
    create-react-app部署到GitHub Pages时报错:Failed to get remote。origin.url
    使用react-redux开发的简单步骤
    使用redux开发的简单步骤
    使用combineReducers注意事项
    在前端页面展示Markdown文件
    React Router V4.0学习笔记
    为什么React事件处理函数必须使用Function.bind()绑定this?
  • 原文地址:https://www.cnblogs.com/nasa/p/1072371.html
Copyright © 2011-2022 走看看