App XAML prend la première fenêtre instancié est la fenêtre principale (ShowDialog est ignorée), je dois montrer plusieurs fenêtres

StackOverflow https://stackoverflow.com/questions/4199932

Question

Je le code suivant dans mon App.xaml.cs

private void App_Start(object sender, StartupEventArgs e)
{
  if ( CompletedInstall())
  {
    //using show to allow for pacifier if loading is slow
    var manager = new WINServiceConfig();
    MainWindow = manager;
    manager.ShowDialog();
  }
}

private bool CompletedInstall()
{
    var window = new Initialize();
    window.ShowDialog();
    return window.DoLaunchManager;
}

et ce qui suit dans le App.xaml

<Application x:Class="Manager.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Startup="App_Start">

Quand je commente la ligne qui vérifie CompletedInstall () manager.ShowDialog () fonctionne bien, et mes spectacles de fenêtre de configuration. Lorsque CompletedInstall () est appelé l'appel à manager.ShowDialog () retourne tout de suite sans afficher la fenêtre. J'ai ajouté la fenêtre principale sur l'hypothèse que quelque part le long de la ligne, quelqu'un a décidé une application ne doit montrer une fenêtre.

J'ai trouvé une solution de contournement en définissant la fenêtre principale avant d'appeler CompletedInstall

        private void App_Start(object sender, StartupEventArgs e)
        {
          var manager = new WINServiceConfig();
          MainWindow = manager;

          if (CompletedInstall())
          {
            manager.ShowDialog();
          }

mais cela me oblige à développer WINServiceConfig (en particulier le constructeur) en fonction de son utilisation, car il ne peut pas compter sur les conditions d'achèvement. C'est une mauvaise forme. Que puis-je faire pour contourner ce problème?

Fenêtre factice? Cela ne peut pas être la meilleure réponse. Peut-il ??

Était-ce utile?

La solution

Vous devez définir le ShutdownMode à OnExplicitShutdown (au moins tout en montrant la boîte de dialogue initiale).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top