4-Graphics_Animation/15-动画基础-1修改按钮动画-P354/MainWindow.xaml.cs

52 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Windows;
using System.Windows.Media.Animation;
namespace _15_动画基础_1修改按钮动画_P354;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonAnimation_OnClick(object sender, RoutedEventArgs e)
{
var doubleAnimation = new DoubleAnimation
{
// 开始值
From = 160,
// 结束值
To = Width - 30,
// 增大10个单位不使用To而是使用By
// By = 10,
// 翻转动画
AutoReverse = true,
// 比原来快5倍
SpeedRatio = 5,
// 持续2秒
Duration = TimeSpan.FromSeconds(2),
// 一直循环
// RepeatBehavior = RepeatBehavior.Forever
// 循环四次
// RepeatBehavior = new RepeatBehavior(4)
// 循环3秒
RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(3))
};
ButtonAnimation.BeginAnimation(WidthProperty, doubleAnimation);
}
private void ButtonAnimation2_OnClick(object sender, RoutedEventArgs e)
{
var doubleAnimation = new DoubleAnimation
{
From = ButtonAnimation.ActualWidth,
To = Width - 30,
Duration = TimeSpan.FromSeconds(2)
};
ButtonAnimation.BeginAnimation(WidthProperty, doubleAnimation);
}
}