Windows手机中同时有多个动画

时间:2012-01-21 16:26:26

标签: windows-phone-7 silverlight-3.0 storyboard

在我的Windows Phone 7.1应用程序中,我试图向用户提供一些反馈,他们通过旋转它来点击堆叠面板。我这样做是通过处理StackPanel的tap事件并从那里创建一个StoryBoard等。看我的代码:

    private void StackPanelTap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        var stackPanel = ((StackPanel) sender);

        var renderTransform = new RotateTransform {Angle = 0,CenterX = 22.5,CenterY = 22.5};
        stackPanel.RenderTransform = renderTransform;

        TimeSpan duration = TimeSpan.FromSeconds(0.30);
        var angleAnimation = new DoubleAnimation { From = 0, To = 360, Duration = duration, AutoReverse = false };

        Storyboard.SetTargetProperty(angleAnimation,new PropertyPath("Angle"));
        Storyboard.SetTarget(angleAnimation,renderTransform);

        var storyboard = new Storyboard();
        storyboard.Children.Add(angleAnimation);
        storyboard.Begin();
    }

这个StackPanel实际上是作为DataTemplate在ItemsControl中(所以我在屏幕上有很多这些StackPanel)。这是xaml

              <Controls:CustomItemsControl  ItemsSource="{Binding Fingers}" Height="2000" Width="330" >
                    <Controls:CustomItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas>                                 
                            </Canvas>
                        </ItemsPanelTemplate>
                    </Controls:CustomItemsControl.ItemsPanel>
                    <Controls:CustomItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Canvas.Top="{Binding Top}" Canvas.Left="{Binding Left}" Tap="StackPanelTap"  Tag="{Binding NoteName}">
                                <Image Source="{Binding Image}"/>
                                <TextBlock Text="{Binding Text}" Margin="10,-45" Foreground="Black" FontSize="32"/>
                            </StackPanel>
                        </DataTemplate>
                    </Controls:CustomItemsControl.ItemTemplate>
                </Controls:CustomItemsControl>

动画效果很好,但只能一次一个。如果我的用户点击多个StackPanel,我想同时拥有多个动画。故事板等可以实现吗?

0 个答案:

没有答案