Is there a way to detect when an animation has finished?

8 posts, 1 answers
  1. Bernhard König
    Bernhard König avatar
    78 posts
    Member since:
    Nov 2009

    Posted 19 Dec 2010 Link to this post

    I looked into the demos but was not really able to find a way to subscribe to an event (or something) to know when an page transition animation has completed.

    It's very important to have this ability mainly on the target page as you won't do any data binding until the animation has finished (or else performance of the animation will suffer).

    If this ability is there, please tell me how I can use it ... or else, please consider it for the final release!

    Ah and yes ... I think the continuum animation is a little bit to straight compared to the native animation. It can be good seen in the Zune app ... the text flowing out makes a more noticable curve mainly in the beginning directing to the bottom of the page compared to your animation.

    Besides that, I think the controls are shaping up very well!

    Thanks,
    Bernhard
  2. Answer
    Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 20 Dec 2010 Link to this post

    Hi Bernhard König,

    There is an event PageTransitionCompleted which can be used in this case. Please let us know if you need more help using it.

    Kind regards,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Bernhard König
    Bernhard König avatar
    78 posts
    Member since:
    Nov 2009

    Posted 21 Dec 2010 Link to this post

    Hi Valentin,

    thanks that's exactly what I need! Didn't found that for some reason ...

    cheers,
    Bernhard
  5. Lukasz
    Lukasz avatar
    9 posts
    Member since:
    Jun 2011

    Posted 05 Jul 2011 Link to this post

    Hi,
    I have problem with good implementation PageTransitionCompleted event.

    For now i published RootFrame and then in Page constructor I am using something like this:
    App.RootFrame.PageTransitionCompleted += new EventHandler<EventArgs>(RootFrame_PageTransitionCompleted);


    But this is not good solution becouse when have for e.g.  5 pages and in contructor for each I make the same += Event then when I came to another page this event will fire to much times.

    I want to fire PageTransitionCompleted for that specyfic page that opens.


    Best regards,
    Łukasz
  6. Bernhard König
    Bernhard König avatar
    78 posts
    Member since:
    Nov 2009

    Posted 05 Jul 2011 Link to this post

    Hi Lukasz,

    yes it's a bit problematic that the event is fired globally by the root frame and cannot be related to the view where the animation was applied on ...

    ... but there's a simple solution - do not subscribe in the constructor but rather in the OnNavigatedTo-Event of the View so your event handler gets attached only and always when your user actually navigates to the page. As soon as the event got raised, unsubscribe the event handler from the event so the even't won't get fired by the same event raised from other views later.

    Subscribe like that:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
            rootFrame.PageTransitionCompleted += PageTransitionCompletedHandler;
    }


    You can unsubscribe as soon as the PageTransitionCompletedHandler gets called and you can also add an additional check if CurrentSource.OriginalString contains the file name of your current view:
    private void PageTransitionCompletedHandler(object sender, EventArgs e)
    {
        if (rootFrame.CurrentSource.OriginalString.Contains("MyView.xaml"))
        {
            // Unsubscribe  
            rootFrame.PageTransitionCompleted -= PageTransitionCompletedHandler;
     
            // Do your stuff here
        }
    }

    So that's pretty solid. This solution didn't cause any problems for me and should do it.
  7. Lukasz
    Lukasz avatar
    9 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Thanks! Work like a charm.
  8. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 06 Jul 2011 Link to this post

    Hello Lukasz,

    Bernhard thanks for answering this one :).

    Can you tell me if we can help you in this scenario? How we can improve the API?

    We can pass the oldPage and newPage as event arguments to the event, but what worries us is that it is too easy to create a memory leak this way. If the developer who consume this event keep a reference to the page it will not be garbage collected - thus a memory leak will be created (which maybe will not be obvious and probably it will be hard to find).

    What do you think? Any ideas are welcome.

    Greetings, Valentin.Stoychev
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  9. Lukasz
    Lukasz avatar
    9 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Hello,

    I think that is not good idea to do this like that. Too problematic I think :)
    I not exactly know how to do this in proper way.
    The best way I think is to check Complited event for this actual page in constructor.  (This solution is in ComponentArt demo - read below)
    Like:
     
    this.TransitionFrame.Complited += Event
    And unsubscribe in Event

    I didn't look deeper how it was done.

    BTW I was talking with Silverlight Toolkit developer team about TransitionFrame.Complited event witch I found in ComponentArt Demo WP7 app. I thought it was default in Silverlight toolkit library  but I was wrong and that event was added by ComponentArt developer to toolkit library. Maybe is that good solution? (Silverlight toolkit developers also think about that :) )

    If you can't find that demo app I can send you by email (I hope I don't break any laws)

    Best regards,
    Lukasz
Back to Top
DevCraft banner