3

I am building an app using WPF and I have 2 animations I want to have delay between them. but when I try to that in the

MainWindow_Loaded(object sender, RoutedEventArgs e)

event, it just delays while loading and I miss the 1st animation.

any help?

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
  • 1
    erik, have you seen that animations have a [BeginTime](http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.begintime.aspx) property? Maybe that helps you with animation start delays. – Clemens Feb 10 '12 at 18:38
  • Take a look at [this answer](http://stackoverflow.com/a/8886941/187955). – Nikola Radosavljević Feb 10 '12 at 16:45

3 Answers3

2

Maybe worth trying would be to invoke the code with animation using the Dispatcher object. By setting the dispatcher priority you can postpone the execution until for example all data bindings (even asynchronous) are completed.

   // Schedule the update function in the UI thread.
   Dispatcher.BeginInvoke(
      System.Windows.Threading.DispatcherPriority.Loaded, ...);

if this does not work try to change the priority - the lower priority the later your action will be invoked.

roberther
  • 436
  • 2
  • 6
1

I have found success with the Window.ContentRendered (or Me.ContentRendered) to find out when the window has finished loading.

See this answer

Community
  • 1
  • 1
donbyte
  • 253
  • 2
  • 6
  • 13
0

There is unfortunately no built-in notification that informs you that loading (binding-rendering) finished. So should come up with your own solution.

One could be in MainWindow_Loaded write something like this (a pseudocode):

new Thread(new ThreadStart(new Action(() =>
{
      Sleep(2000); // a couple of seconds sleep 
      StartAnimation(); 

}))).Start();

Hope this helps.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Well, code does not work, but i guess it's because i don't know much about working with Threads, but it sure answers the quetsion thank you. – eric.itzhak Feb 10 '12 at 16:57