This is a migrated thread and some comments may be shown as answers.

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

7 Answers 137 Views
TransitionControl
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bernhard König
Top achievements
Rank 2
Bernhard König asked on 19 Dec 2010, 03:35 PM
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Valentin.Stoychev
Telerik team
answered on 20 Dec 2010, 11:14 AM
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.
0
Bernhard König
Top achievements
Rank 2
answered on 21 Dec 2010, 08:19 PM
Hi Valentin,

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

cheers,
Bernhard
0
Lukasz
Top achievements
Rank 1
answered on 05 Jul 2011, 06:49 PM
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
0
Bernhard König
Top achievements
Rank 2
answered on 05 Jul 2011, 08:04 PM
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.
0
Lukasz
Top achievements
Rank 1
answered on 06 Jul 2011, 07:19 AM
Thanks! Work like a charm.
0
Valentin.Stoychev
Telerik team
answered on 06 Jul 2011, 08:58 AM
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!

0
Lukasz
Top achievements
Rank 1
answered on 06 Jul 2011, 10:06 AM
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
Tags
TransitionControl
Asked by
Bernhard König
Top achievements
Rank 2
Answers by
Valentin.Stoychev
Telerik team
Bernhard König
Top achievements
Rank 2
Lukasz
Top achievements
Rank 1
Share this question
or