我有一个示例故事板,我想知道如何仅使用代码来实现,但我无法弄清楚。这是 WPF/XAML,任何指针将不胜感激。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True"
WindowStyle="None"
Title="MainWindow" Height="350" Width="525" Background="Transparent" Topmost="True" WindowState="Maximized" ResizeMode="NoResize">
<Canvas Name="canvas1">
<Button Canvas.Left="145" Canvas.Top="155" Content="Button" Height="23" Name="Button1" Width="75">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Button1" Storyboard.TargetProperty="Width" AutoReverse="true" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="300"/>
<SplineDoubleKeyFrame KeyTime="00:00:10" Value="100"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation
Storyboard.TargetName="Button1"
Storyboard.TargetProperty="(Canvas.Left)"
From="100" To="600" Duration="0:0:10" AutoReverse="true" RepeatBehavior="Forever"/>
<DoubleAnimation
Storyboard.TargetName="Button1"
Storyboard.TargetProperty="(Canvas.Top)"
From="100" To="600" Duration="0:0:10" AutoReverse="true" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Canvas>
</Window>