希望这是有道理的。
我有这样的事情:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!Directory.Exists(dataFolder))
{
Directory.CreateDirectory(dataFolder);
}
try
{
using (DataContext context = new DataContext())
{
context.Database.CreateIfNotExists();
}
}
catch (IOException ex)
{
}
KeyProgram.Show();
if (Manager.KeyExists == true)
{
MainWindowViewModel viewModel = new MainWindowViewModel();
this.MainWindow = new MainWindow();
this.MainWindow.DataContext = viewModel;
this.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose;
Helper.WindowDialogService.SetOwner(this.MainWindow);
viewModel.Init();
this.MainWindow.Show();
}
else {
Console.WriteLine("Please try again");
}
}
在显示我的 licensekey 窗口后,我想中断以便系统需要用户输入(让用户输入许可证密钥)然后继续运行 if-else 语句(在 if (LicenseKeyManager.licenseKeyExists == true))。
然而,目前,onStartup,应用程序只是首先运行所有代码,然后如果我输入密钥并验证它,它不会运行该 if 语句,因为它已经运行了。
在继续执行该 if 语句之前,如何从视图中中断用户输入?
现在在 LicenseKeyProgram.Show() 之后,如果我在 if 语句处设置断点,应用程序将不会让用户输入任何内容,因为它卡在加载中(无法在窗口上执行任何操作)。
我在这里需要一个事件处理程序还是...?