0
目前我在我的WPF应用程序中有一个奇怪的行为。 我有一个主窗口和一个设置对话框。我可以显示设置对话框,但是当我关闭它时,我的主窗口也会关闭,应用程序退出。为什么关闭对话框关闭主窗口
应用程序的ShutdownMode是OnMainWindowClose。但这也发生在OnLastWindowClose。
这是我的控制器类的代码控制的主窗口和设置窗口:
public class MainWindowController : IDisposable, IMainWindowController
{
private readonly MainWindowViewModel mainWindowViewModel;
private readonly MainWindow mainWindow;
private IoAdapter ioAdapter;
public MainWindowController()
{
this.mainWindowViewModel = new MainWindowViewModel(this);
this.mainWindow = new MainWindow { DataContext = this.mainWindowViewModel };
}
public void ShowMainWindow()
{
mainWindow.Show();
}
public void ShowSettingsWindow()
{
var viewModel = new SettingsWindowViewModel();
var settingsWindow = new SettingsWindow { DataContext = viewModel, Owner = this.mainWindow};
var showDialog = settingsWindow.ShowDialog();
if (showDialog != null && showDialog.Value)
{
// Apply Settings
}
}
如果您完全删除ShowMainWindow方法,它的行为如何?我认为这是不需要的,因为主窗口将在开始时显示。应用设置中的代码如何? –
我需要用Show()显示mainWindow,因为我删除了App.xaml中的StartUpUri。目前没有任何应用设置的代码。只有评论 – Noffls
是的,如果你按照我说的做,并将其读取到app.xaml,你可以重现或正常工作吗? –