...但是它没有任何意义。T-T
在我的Application_Startup
事件处理程序中,我有类似这样的代码:
private void Application_Startup(object sender, StartupEventArgs e)
{
string errorMessage;
if(CheckStartUpConditions(out errorMessage))
{
(new MainWindow()).Show();
}
else
{
MessageBox.Show(errorMessage, "Application Startup",
MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
}
}
private bool CheckStartUpConditions(out string errorMessage)
{
errorMessage = string.Empty;
if(...)
errorMessage += "Please login to xxx. ";
if(...)
errorMessage += "Please install xxx.";
if(string.IsNullOrEmpty(errorMessage))
return true;
else
return false;
}
消息框出现了一瞬间,然后就消失了。它不等待我点击“确定”或“X”按钮。我真的对为什么会发生这种情况感到困惑,所以非常感谢任何帮助。
我已经尝试注释掉对 Shutdown
的调用,但它仍然表现出相同的方式。
此外,应用程序还有一个 SplashScreen
,所以我不知道是否影响了这个问题。
编辑:我添加了更多代码,如果有帮助的话。消息框显示了正确的错误信息,只是不停留足够长的时间供用户阅读。 >:(
第二次编辑:好的...我想我已经找到了罪魁祸首。 :( 我将用作启动画面的图像的构建操作从 SplashScreen 更改为 None,现在消息框将保持并等待用户输入。我不明白为什么 SplashScreen 会影响 MessageBox。 >:(