Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

See this answer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top