下面是一个非常简单的示例,单击按钮时按钮高度\宽度增加,鼠标离开控件时缩小.WPF中的动画是使用StoryBoards完成的.故事板通常位于EventTriggers中,可以保存在控件,窗口,页面或应用程序的资源中.以下是一些示例以及一些资源:
<Window x:Class="WPFFeatureSample_Application.AnimationWindowSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AnimationWindowSample" Height="300" Width="300">
<Grid>
<Button Content="Sample" Width="50" Height="50">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="200" Storyboard.TargetProperty="Width"></DoubleAnimation>
<DoubleAnimation To="200" Storyboard.TargetProperty="Height"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="50" Storyboard.TargetProperty="Width"></DoubleAnimation>
<DoubleAnimation To="50" Storyboard.TargetProperty="Height"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
Run Code Online (Sandbox Code Playgroud)
参考文献:
http://msdn.microsoft.com/en-us/library/ms742868.aspx
http://windowsclient.net/learn/