Friday, 27 September 2013

WPF splashscreen active when form is loaded

WPF splashscreen active when form is loaded

I'm using a splashscreen with the following code:
var splashScreen = new SplashScreen("/Resources/enetricity.png");
splashScreen.Show(false);
InitializeComponent();
DataContext = viewModel;
// pump until loaded
PumpDispatcherUntilPriority(DispatcherPriority.Loaded);
// start a timer, after which the splash can be closed
var splashTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(2)
};
splashTimer.Tick += (s, e) =>
{
splashTimer.Stop();
splashScreen.Close(splashTimer.Interval);
};
splashTimer.Start();
private static void PumpDispatcherUntilPriority(DispatcherPriority
dispatcherPriority)
{
var dispatcherFrame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke((ThreadStart)(() =>
dispatcherFrame.Continue = false), dispatcherPriority);
Dispatcher.PushFrame(dispatcherFrame);
}
But this is what happens: the splashscreen shows up, then the window shows
up and the splashscreen is back, and then after some time its gone. The
timer is good, when the splashscreen the second time is gone, all modules
and UI are loaded. But I don't want to see my window already.. So it
should only show up once
Greets

No comments:

Post a Comment