Windows Phone 8.1 动画

network | | 访问(37)
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,35,0,28">
        <TextBlock Text="我的应用程序" FontSize="20"  />
        <TextBlock Text="动画" FontSize="60" />
    </StackPanel>

    <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <StackPanel.Resources>
            <Storyboard x:Name="myStoryboard">
                <DoubleAnimation From="0" To="300" EnableDependentAnimation="True"
                                     AutoReverse="True" RepeatBehavior="Forever" 
                                     Duration="0:0:3" Storyboard.TargetName="rect" 
                                     Storyboard.TargetProperty="Width" />
            </Storyboard>
        </StackPanel.Resources>
        <Rectangle  x:Name="rect" Width="0" Fill="Red"  Height="100" />
        <Button  Content="启动动画" Click="Button_Click_1"  />
    </StackPanel>
</Grid>
private void Button_Click_1(object sender, RoutedEventArgs e) {
    myStoryboard.Begin();
}