Note that there are some explanatory texts on larger screens.

plurals
  1. POStartup displaying a modal window followed by a standard window
    primarykey
    data
    text
    <p>I am launching an MVVM application with code in the App.xaml.cs like so:</p> <pre><code>protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //Set data directory string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\BlowTrial"; if (!Directory.Exists(baseDir)) { Directory.CreateDirectory(baseDir); } AppDomain.CurrentDomain.SetData("DataDirectory", baseDir); //Application initialisation AutoMapperConfiguration.Configure(); //Security CustomPrincipal customPrincipal = new CustomPrincipal(); AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal); // Create the ViewModel to which // the main window binds. var mainWindowVm = new MainWindowViewModel(); MainWindow window = new MainWindow(mainWindowVm); // When the ViewModel asks to be closed, // close the window. EventHandler handler = null; handler = delegate { window.Close(); if (!window.IsLoaded) //in case user cancelled close event { mainWindowVm.RequestClose -= handler; } }; mainWindowVm.RequestClose += handler; window.Show(); } </code></pre> <p>I would like to test for the existence of entities containing important data for running the application, and if these do not exist, run a wizard (as a dialog) which obtains these settings:</p> <pre><code>if (BlowTrialDataService.GetBackupDetails().BackupData == null || !_repository.LocalStudyCentres.Any()) { DisplayAppSettingsWizard(); } static void DisplayAppSettingsWizard() { //testfor and display starup wizard var wizard = new GetAppSettingsWizard(); GetAppSettingsViewModel appSettings = new GetAppSettingsViewModel(); wizard.DataContext = appSettings; EventHandler wizardHandler = null; wizardHandler = delegate { wizard.Close(); wizard = null; appSettings.RequestClose -= wizardHandler; }; appSettings.RequestClose += wizardHandler; wizard.ShowDialog(); } </code></pre> <p>When I place this code in the MainWindow.xaml.cs, the application runs correctly. When it is placed in either the App.xaml.cs (before the code to instantiate the instance of MainWindow), or in the constructor for MainWindowViewModel, the wizard displays correctly, but the application ends without displaying the MainWindow on completion of the wizard. If there is no cause to display the wizard, MainWindow displays correctly in all cases.</p> <p>Examining the debug output, there are no errors of note (a few first chance exceptions related to sql commands).</p> <p>Is there a reason for this - having the code in the code behind MainWindow.xaml does not seem the most logical place (which to my mind would be the app.xaml.cs).</p> <p>Thank you for your expertise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload