zoukankan      html  css  js  c++  java
  • WPF StoryBoard用法

    时间:2011-06-15 21:26来源:百度空间 作者:shichen4 点击:
    StoryBoard使用,Xaml转cs代码 Canvas.Triggers EventTriggerRoutedEvent= Image.MouseLeftButtonDown EventTrigger.Actions BeginStoryboard StoryboardStoryboard.TargetName= image1 Storyboard.TargetProperty= (Canvas.Left) DoubleAnimationAutoReverse= True Rep
      

      StoryBoard使用,Xaml转cs代码

    <Canvas.Triggers>
                    <EventTrigger RoutedEvent="Image.MouseLeftButtonDown">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard Storyboard.TargetName="image1" 
                                                    Storyboard.TargetProperty=
    "(Canvas.Left)" >
                                    <DoubleAnimation AutoReverse="True" 
    RepeatBehavior=
    "Forever" 
                                                             BeginTime=
    "0" 
    Duration=
    "0:0:20" From="0" To="-1100">
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </Canvas.Triggers>

      转换为cs代码:

             this.image1.RenderTransform = new TranslateTransform();

                this.image1.Name = "image1";
                NameScope.SetNameScope(this,new NameScope());
                this.RegisterName(this.image1.Name,this.image1);

                DoubleAnimation xAnimation = new DoubleAnimation();
                xAnimation.From = 0;
                xAnimation.To = -1100;
                xAnimation.Duration = new Duration(TimeSpan.FromSeconds(30));

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

                Storyboard story = new Storyboard();
                story.AutoReverse = true;
                story.RepeatBehavior = RepeatBehavior.Forever;
                story.Children.Add(xAnimation);

                Storyboard.SetTargetName(xAnimation,this.image1.Name);
                Storyboard.SetTargetProperty(xAnimation,new PropertyPath("(0).(1)",propertyChain));

                story.Begin(this);
  • 相关阅读:
    HDOJ1556 Color the ball
    BUPT( 北邮)2 大数 AB
    DateTime.ToString()的用法
    判断DataTable中的空值(字段为数值型)?
    [转].NET平台下的Excel编程|C#操作Excel|Application和ApplicationClass的联系和区别
    [转]寻找SqlHelper
    C#认识/理解/运用 StreamReader,StreamWriter,StringReader,StringWriter[转]
    C# 应用微软的Visual Studio International Pack 类库提取汉字拼音首字母[转]
    [转]想靠写程序赚更多钱,写到两眼通红,写得比别人都又快又好好几倍,结果又能如何?
    DataRow复制一行到另一个DataTable[转]
  • 原文地址:https://www.cnblogs.com/changbaishan/p/3307942.html
Copyright © 2011-2022 走看看