title: WPF splash screen until windows ends loading
body: <p>I have an application that consumes a lot of time when the window loading.
  In the Window_load event, I read from the database the state and the name of some controls.
  I want to do a splash screen that will ends after the window will fully load.</p>
  
  <p>I have tried with this example <a href="http://www.codeproject.com/KB/dialog/wpf_animated_text_splash.aspx" rel="nofollow">http://www.codeproject.com/KB/dialog/wpf_animated_text_splash.aspx</a> but the splash screen closes before the main window is fully loaded and my mainwindow appears in white and is not fully loaded.</p>
  
  <p>I am beginner in wpf, and I don't know how can I have a splash screen which remain on the screen until the main window fully loads.</p>
  
  <p>Please give me an example.</p>
  
  <p>My Splash Screen Code:</p>
  
  <pre><code>public partial class SplashWindow : Window
      {
          Thread loadingThread;
          Storyboard Showboard;
          Storyboard Hideboard;
          private delegate void ShowDelegate(string txt);
          private delegate void HideDelegate();
          ShowDelegate showDelegate;
          HideDelegate hideDelegate;
  
          public SplashWindow()
          {
              InitializeComponent();
              showDelegate = new ShowDelegate(this.showText);
              hideDelegate = new HideDelegate(this.hideText);
              Showboard = this.Resources["showStoryBoard"] as Storyboard;
              Hideboard = this.Resources["HideStoryBoard"] as Storyboard;
  
          }
  
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              loadingThread = new Thread(load);
              loadingThread.Start();
          }
          private void load()
          {
              Thread.Sleep(6000);
  
              this.Dispatcher.Invoke(showDelegate, "first data to loading");
              Thread.Sleep(6000);
              //load data 
              this.Dispatcher.Invoke(hideDelegate);
  
              Thread.Sleep(6000);
              this.Dispatcher.Invoke(showDelegate, "second data loading");
              Thread.Sleep(6000);
              //load data
              this.Dispatcher.Invoke(hideDelegate);
  
  
              Thread.Sleep(6000);
              this.Dispatcher.Invoke(showDelegate, "last data loading");
              Thread.Sleep(6000);
              //load data 
              this.Dispatcher.Invoke(hideDelegate);
  
  
  
              //close the window
              Thread.Sleep(6000);
              this.Dispatcher.Invoke(DispatcherPriority.Normal,(Action)delegate() { Close(); });
          }
          private void showText(string txt)
          {
              txtLoading.Text = txt;
              BeginStoryboard(Showboard);
          }
          private void hideText()
          {
              BeginStoryboard(Hideboard);
          }
  
      }
  </code></pre>
  
  <p>And this splash screen I will call in my MainWindow constructor:</p>
  
  <pre><code>new SplashWindow().ShowDialog();
  </code></pre>
  
  <p>But my MainWindow Load function will run after the Splash Window will finish to be showed.</p>
  
  <p>Thank you!</p>