我正在使用带有以下代码的启动画面:
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都被加载。但我不想看到我的窗户......所以它应该只出现一次
迎接
答案 0 :(得分:1)
这是另一种方法(可能比你想做的要简单得多):
App.xaml.cs
中首先创建并显示启动画面(例如,在Startup
事件中)