如何在WPF中设置动画控制?

ato*_*erz 4 c# wpf animation controls

我见过一个我找不到的样本WPF程序.在此示例中,当我单击按钮时,另一个按钮开始增长和缩小.意思是我可以用表格做其他事情.我该怎么做呢?

rfr*_*sia 9

下面是一个非常简单的示例,单击按钮时按钮高度\宽度增加,鼠标离开控件时缩小.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/