[英]OpenFileDialog in Application Startup closing immediately
我想通过在应用程序启动时在我的解决方案中加载一些由另一个项目序列化的文件:
App.xaml.cs:
<Application (...)
Startup="Application_Startup">
</Application>
Application_Startup方法:
private void Application_Startup(object sender, StartupEventArgs e)
{
(...)
if (Environment.GetCommandLineArgs().Contains("C"))
{
if (Directory.Exists(Settings.Default.SavedPath) && Directory.GetFiles(Settings.Default.SavedPath, "*.extension").Length == 0)
// do sth
else
{
var result = MessageBox.Show("somerror", "Error!",
MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);
if (result == MessageBoxResult.Yes)
OpenUserConfig();
else
Shutdown();
}
}
(..)
}
OpenUserConfig方法:
private void OpenUserConfig()
{
var dial = new OpenFileDialog();
if (dial.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
//do sth
}
这两个方法在App类中,因此存在问题:
弹出消息框和文件对话框几秒钟后便消失了。
我想找到用于消息框的解决方案(通过使用MessageBoxOptions.DefaultDesktopOnly),但是我无法维持OpenFileDialog应该怎么办?
另外(这可能很重要-我不知道):我的应用程序中有SplashScreen。
您可以使用对话框创建自己的表单,然后打开此表单。 这是最快的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.