XAML代码:
<Window x:Class="关键帧动画.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="" Loaded="Window_Loaded">
<Grid>
<Border Height="" Width="" Background="#326939" Name="border1"/>
</Grid>
</Window>
.CS代码:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation; namespace 关键帧动画
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
// 在此处添加事件处理程序实现。
DoubleAnimationUsingKeyFrames dak=new DoubleAnimationUsingKeyFrames();
dak.KeyFrames.Add(new LinearDoubleKeyFrame(,KeyTime.FromTimeSpan(TimeSpan.FromSeconds())));
dak.KeyFrames.Add(new LinearDoubleKeyFrame(,KeyTime.FromTimeSpan(TimeSpan.FromSeconds())));
dak.KeyFrames.Add(new LinearDoubleKeyFrame(,KeyTime.FromTimeSpan(TimeSpan.FromSeconds())));
dak.KeyFrames.Add(new LinearDoubleKeyFrame(,KeyTime.FromTimeSpan(TimeSpan.FromSeconds())));
dak.BeginTime=TimeSpan.FromSeconds();
dak.RepeatBehavior=new RepeatBehavior();
this.border1.BeginAnimation(Border.WidthProperty,dak);
}
}
}