3

Basically my application does a lot of things within LOADED event of the main window.

I just want to show some splash screen during this time (LOADED event) and don't show main window at all.

I found some example here http://www.codeproject.com/Articles/38291/Implement-Splash-Screen-with-WPF but it is not a good one. This tip is also doesn't cover my purpose.

Also I'd like to display each stage what I do under the LOADED event under the splash screen. So I thought adding a status update to the splash screen. Each completed task will update a splash screen status label.

Any clue how it could be done?

Thank you!

Community
  • 1
  • 1
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • 1
    Can't you just have a normal window that acts as a splash screen? Start up with that window and update its content within the "main" window's loaded event. – Eren Ersönmez May 23 '12 at 13:55

2 Answers2

2

here is the little code for you.

  void TemplateSelector_Loaded(object sender, RoutedEventArgs e)
        {
            showWin();

            Thread.Sleep(10000);


            CloseWin();

        }

        private void CloseWin()
        {
            WindowManager.Close();
        }
        Window tempWindow = new Window();
        public void showWin()
        {
            WindowManager.LaunchWindowNewThread<SplashWindow>();

        }
    }

    public class WindowManager
    {
        private static Window win;
        public static void LaunchWindowNewThread<T>() where T : Window, new()
        {
            Thread newWindowThread = new Thread(ThreadStartingPoint);
            newWindowThread.SetApartmentState(ApartmentState.STA);
            newWindowThread.IsBackground = true;

            Func<Window> f = delegate
            {
                T win = new T();
                return win;
            };

            newWindowThread.Start(f);
        }

        private static void ThreadStartingPoint(object t)
        {
            Func<Window> f = (Func<Window>)t;
            win = f();

            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.Topmost = true;
            win.Show();
            Dispatcher.Run();
        }
        public static void Close()
        {

            if (win != null)
                win.Dispatcher.BeginInvokeShutdown(DispatcherPriority.Send);

        }
    }

you can modify as you wish.

JSJ
  • 5,653
  • 3
  • 25
  • 32
1

I found some cool solution here http://plaincolumn.blogspot.com/2009/11/wpf-splash-screen-with-status-update.html

So it fits my needs 100%.

NoWar
  • 36,338
  • 80
  • 323
  • 498