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); }
网上下载的动画例子,不过只有放在构造函数中才会有动画的效果,我现在想在点击按钮后触发这个效果,谁能指点下啊
把这段代码独立成一个函数,然后在点击按钮的地方调用运行,不可以吗?