我正在使用带有以下代码的启动画面:
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);
}
但这就是发生的情况:闪屏出现,然后窗口出现,闪屏又回来了,然后过了一段时间就消失了。计时器很好,当第二次启动画面消失时,所有模块和 UI 都已加载。但我不想看到我的窗口了..所以它应该只出现一次
问候