locked
How to reset the storyboard (Which is present in datatemplate trigger ) before navigating to other page. RRS feed

  • Question

  • Hi,

    I have a data template for gridview which contains several stack panels. I have implemented one storyboard in one of those stackpanels using event triggers. Storyboard animations works fine, but the problem is if I click on the gridview items it will navigate to the other page while coming back to my homePage (Where this gridView lives) the gridview items are not reset to initial position and again storyboard animations will apply on it, as it is present in event trigger causes malfunction of storyboard animations. Hope it's clear. my code is mentioned below. Now, I want to reset the gridview items to initial postion after coming back to my homepage.

    could anyone please help me to solve this issue?

            <DataTemplate x:Key="NewsItemTemplateAnimation">
                <StackPanel >
                    
                    <StackPanel >
                        <StackPanel >
                            <Image "/>
                            
                        </StackPanel>
                        <StackPanel >
                            <TextBlock >
                            <TextBlock >
                        </StackPanel>
                        
                        <StackPanel >
                            
                            <Button  />
                            <Button />
                            <Button  />
                         </StackPanel >   
                        <StackPanel.RenderTransform>
                            <TranslateTransform x:Name="panel1" Y="0" />
                        </StackPanel.RenderTransform>
                    </StackPanel>
                    <StackPanel  >
                        <Image  />
                        <StackPanel.RenderTransform>
                            <TranslateTransform x:Name="panel2" Y="0" />
                        </StackPanel.RenderTransform>
                        <StackPanel.Triggers>
                            <EventTrigger x:Name="evttrigger"  RoutedEvent="StackPanel.Loaded" >
                                <BeginStoryboard>
                                    <Storyboard x:Name="NewsAnimationSB" Duration="0:0:20" AutoReverse="True" RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:10"  Storyboard.TargetName="panel1" Storyboard.TargetProperty="Y">
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.100" Value="0"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.200" Value="-10"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.300" Value="-20"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.400" Value="-30"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.500" Value="-40"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.600" Value="-50"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.700" Value="-60"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.800" Value="-70"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.900" Value="-80"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.000" Value="-90"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.100" Value="-100"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.200" Value="-110"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.300" Value="-120"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.400" Value="-130"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.500" Value="-140"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.600" Value="-150"/>
                                        </DoubleAnimationUsingKeyFrames>
    
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:10" Storyboard.TargetName="panel2" Storyboard.TargetProperty="Y">
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.100" Value="0"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.200" Value="-10"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.300" Value="-20"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.400" Value="-30"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.500" Value="-40"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.600" Value="-50"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.700" Value="-60"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.800" Value="-70"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:0.900" Value="-80"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.000" Value="-90"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.100" Value="-100"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.200" Value="-110"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.300" Value="-120"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.400" Value="-130"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.500" Value="-140"/>
                                            <LinearDoubleKeyFrame KeyTime="00:00:1.600" Value="-150"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </StackPanel.Triggers>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
    

    Tuesday, August 26, 2014 5:57 AM

Answers

  • Hi Badri,

    To find the stackpanel in DataTemplate you could work together with VisualTreeHelper, see this blog for more information: http://blog.jerrynixon.com/2012/09/how-to-access-named-control-inside-xaml.html

    But i'm not quite understand what do you mean by reset the storyboard here, could you explain more? As I know you can Stop and Begin to make the storyboard works like reset.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 27, 2014 8:51 AM
    Moderator