Xaml 轴内LongListSelector控件中的动画

Xaml 轴内LongListSelector控件中的动画,xaml,windows-phone-8,Xaml,Windows Phone 8,我有一个Pivot控件,它有三个PivotItem,它们都是LongListSelector,现在我需要在首先加载的任何Pivot项上显示特定类型的动画,即在启动或导航回页面时显示给用户的项。为此,我在pivot控件上附加了一个loaded事件,该事件在加载控件时为我提供了显示的PivotItem,并在此基础上为pivot项内的LongListSelecor提供了数据模板 private async void MainPivot_Loaded(object sender, Rout

我有一个Pivot控件,它有三个PivotItem,它们都是LongListSelector,现在我需要在首先加载的任何Pivot项上显示特定类型的动画,即在启动或导航回页面时显示给用户的项。为此,我在pivot控件上附加了一个loaded事件,该事件在加载控件时为我提供了显示的PivotItem,并在此基础上为pivot项内的LongListSelecor提供了数据模板

       private async void MainPivot_Loaded(object sender, RoutedEventArgs e)
    {
        var sen = (Pivot)sender;

        for (int k = 0; k < sen.Items.Count; k++)
        {
            if (k == sen.SelectedIndex)
            {
                var navigatingTo = (LongListSelector)((PivotItem)((Pivot)sender).SelectedItem).Content;
                navigatingTo.ItemTemplate = Resources["AnimationDataTemplate"] as DataTemplate;

            }
            else
                ((LongListSelector)((PivotItem)sen.Items[k]).Content).ItemTemplate = Resources["DefaultDataTemplate"] as DataTemplate;

        }
    }
private async void mainprovot\u已加载(对象发送方,路由目标)
{
var sen=(Pivot)发送方;
对于(int k=0;k
我有两个数据模板,一个没有动画

        <DataTemplate x:Key="DefaultDataTemplate">
        <StackPanel x:Name="Panel" Background="#f5f5f5" Width="430" Margin="2,0,0,10">

            <StackPanel Orientation="Horizontal">
                <Rectangle Fill="{Binding Condition, Converter={StaticResource conditionToColor}}" Height="Auto" Width="5"/>
                <StackPanel Margin="10,10,0,10" Height="{Binding  Converter={StaticResource conditionToStackPanelHeight}}" Width="330">
                    <TextBlock x:Name="Text1" Text="{Binding LineOne}" Foreground="#5ac8d5" FontFamily="Lato" FontWeight="SemiBold" FontSize="{Binding  Converter={StaticResource conditionToMainTextFontSize}}" Width="330" TextAlignment="Left" TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToMainTextMargin}}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                    <TextBlock x:Name="Text2" Text="Hospital" Foreground="#8fa7b3" FontSize="{Binding  Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                    <TextBlock x:Name="Text3" Text="Visited on" Foreground="#8fa7b3" FontSize="{Binding  Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                    <TextBlock x:Name="Text4" Text="By" Foreground="#8fa7b3" FontSize="{Binding  Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                </StackPanel>
                <Image Source="Assets/Images/SmallMale.png" Height="{Binding  Converter={StaticResource conditionToImageHeight}}" Margin="{Binding  Converter={StaticResource conditionToImageMargin}}" Opacity="0.25" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

还有一个是动画

<DataTemplate x:Key="AnimationDataTemplate">
        <StackPanel x:Name="PanelToAnimate" Background="#f5f5f5" Width="430" Margin="622,0,-622,10" Loaded="PanelToAnimate_Loaded" Unloaded="PanelToAnimate_Unloaded">
            <StackPanel.Resources>

                <Storyboard x:Name="myStackPanelboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="PanelToAnimate">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="-620"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

                <Storyboard x:Name="EndStoryBoard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetX)" Storyboard.TargetName="PanelToAnimate">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="620"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </StackPanel.Resources>
            <StackPanel.Projection>
                <PlaneProjection/>
            </StackPanel.Projection>

            <StackPanel Orientation="Horizontal">
                <Rectangle Fill="{Binding Condition, Converter={StaticResource conditionToColor}}" Height="Auto" Width="5"/>
                <StackPanel Margin="10,10,0,10" Height="{Binding Converter={StaticResource conditionToStackPanelHeight}}" Width="330">
                    <TextBlock x:Name="Text1" Text="{Binding LineOne}" Foreground="#5ac8d5" FontFamily="Lato" FontWeight="SemiBold" FontSize="{Binding Converter={StaticResource conditionToMainTextFontSize}}" Width="330" TextAlignment="Left" TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToMainTextMargin}}" Style="{StaticResource PhoneTextExtraLargeStyle}">
                        <TextBlock.Projection>
                            <PlaneProjection/>
                        </TextBlock.Projection>
                    </TextBlock>
                    <TextBlock x:Name="Text2" Text="Hospital" Foreground="#8fa7b3" FontSize="{Binding  Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}">
                        <TextBlock.Projection>
                            <PlaneProjection/>
                        </TextBlock.Projection>
                    </TextBlock>
                    <TextBlock x:Name="Text3" Text="Visited on" Foreground="#8fa7b3" FontSize="{Binding Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}">
                        <TextBlock.Projection>
                            <PlaneProjection/>
                        </TextBlock.Projection>
                    </TextBlock>
                    <TextBlock x:Name="Text4" Text="By" Foreground="#8fa7b3" FontSize="{Binding Converter={StaticResource conditionToSubTextFontSize}}"  Width="330" TextAlignment="Left"  TextWrapping="Wrap" Margin="{Binding  Converter={StaticResource conditionToSubTextMargin}}" Style="{StaticResource PhoneTextSubtleStyle}">
                        <TextBlock.Projection>
                            <PlaneProjection/>
                        </TextBlock.Projection>
                    </TextBlock>
                </StackPanel>
                <Image Source="Assets/Images/SmallMale.png" Height="{Binding Converter={StaticResource conditionToImageHeight}}" Margin="{Binding Converter={StaticResource conditionToImageMargin}}" Opacity="0.25" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

“AnimationDataTemplate”中的StackPanel有一个loaded事件,我在其中执行故事板开始的逻辑,当应用程序启动时,我让Panel将Animate_loaded事件设置为7次,如果所有LongListSelector中都有7个项目,那么现在如果我导航到(假设我在第一个数据透视项LongListSelector中,从那里我转到第二个数据透视项LongListSelector并从那里导航) 从下一页返回,我将PanelToAnimate_加载事件激发14次,但longlistselector中的项为7


有人能帮我解决这个问题吗?

这个问题很好,可惜没有人回答:(