首页新闻找找看学习计划

wpf 点击按钮后触发动画

0
悬赏园豆:10 [已解决问题] 解决于 2013-07-16 09:54

this.Loaded += new RoutedEventHandler(Login_DongHua);

 void Login_DongHua(object sender, RoutedEventArgs e)
        {
            this.donghua.RenderTransform = new TranslateTransform();

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

            DoubleAnimation xAnimation = new DoubleAnimation();
            xAnimation.From = 0;
            xAnimation.To = -160;
            xAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

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

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

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

            story.Begin(this);
        }

网上下载的动画例子,不过只有放在构造函数中才会有动画的效果,我现在想在点击按钮后触发这个效果,谁能指点下啊

夼中玥的主页 夼中玥 | 初学一级 | 园豆:120
提问于:2012-06-11 19:05
< >
分享
最佳答案
0

把这段代码独立成一个函数,然后在点击按钮的地方调用运行,不可以吗?

收获园豆:10
无之无 | 大侠五级 |园豆:5085 | 2012-06-12 08:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册