System.Windows.MessageBox不等待用户输入才去噗! [英] System.Windows.MessageBox doesn't wait for user input before going poof!
问题描述
...这是没有意义的原因。 TT
...and it makes no sense why. T-T
在我的 Application_Startup
事件处理程序我有一些代码看起来有点像这样:
In my Application_Startup
event handler I have code that looks kinda like this:
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按钮。我真的很为难,为什么这正在发生,所以任何帮助会的不胜感激的。
我试着注释掉调用关闭
只是踢和笑声,它仍然表现相同方式。
I've tried commenting out the call to Shutdown
just for kicks and giggles, and it still behaves the same way.
此外,应用程序也有一个闪屏
,所以我不知道这是否影响这一点。
Also, the application also has a SplashScreen
, so I don't know if that's effecting this.
编辑:我添加了更多的代码是否有帮助。该消息框显示正确的错误消息。只是不会停留足够长的用户阅读。 >:(
I added more code if that helps. The message box is showing the correct error message. Just won't stay long enough for the users to read it. >:(
编辑第2部分:好吧...我想我已经找到了罪魁祸首:(我改变了我使用的图像生成操作从闪屏我飞溅到无,消息框现在会留下来,等待用户输入,我不明白为什么闪屏与MessageBox的拧>:(
EDIT PART 2: Okay...I think I've found the culprit. :( I changed the build action on the image I'm using as my splash from SplashScreen to None and the message box will now stay and wait for user input. I don't understand why the SplashScreen is screwing with the MessageBox. >:(
推荐答案
尝试使用接受 IWin32Window
参数的重载,并通过空
价值使您的MessageBox您的应用程序,它是独立于所有其他窗口可能存在的顶层窗口。我想你的MessageBox得到由闪屏的形式持有。当启动画面关闭时,该框架将关闭消息框,所以让你的MessageBox无主应该做的伎俩。
Try to use an overload that accepts IWin32Window
parameter and pass Null
value to make your MessageBox a top-level window of your application, which is independent of all other windows that may exist. I guess your MessageBox gets owned by splashscreen form. When splashscreen is closed, the framework closes the MessageBox. So making your MessageBox ownerless should do the trick.
这篇关于System.Windows.MessageBox不等待用户输入才去噗!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!