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,你可以重現或正常工作嗎? –