adonis-ui icon indicating copy to clipboard operation
adonis-ui copied to clipboard

MessageBox result closes application

Open UranusDarkness opened this issue 2 years ago • 3 comments

I'm trying to use the AdonisUI.Controls.MessageBox for my AutoUpdater, but even though the result is true in the if statement, the code keeps going on until the OnExit event. For example: I click on Yes when it asks me to update, and instead of showing the Window, it closes the application

 messageBox = new MessageBoxModel{
                            Text = $@"There is new version {args.CurrentVersion} available. You are using version {args.InstalledVersion}. Do you want to update the application now?",
                            Caption = @"Update Available",
                            Icon = AdonisUI.Controls.MessageBoxImage.Information,
                            Buttons = MessageBoxButtons.YesNo(),
                        };

                        AdonisUI.Controls.MessageBox.Show(messageBox);

if (messageBox.Result.Equals(AdonisUI.Controls.MessageBoxResult.Yes) || messageBox.Result.Equals(AdonisUI.Controls.MessageBoxResult.OK)) {
                        try
                        {
                            if (Models.AutoUpdater.DownloadUpdate(args))
                            {
                                AutoUpdateWindow autoUpdateWindow = new AutoUpdateWindow();
                                autoUpdateWindow.Show();
                            }

                        }
                        catch (Exception exception)
                        {
                            AdonisUI.Controls.MessageBox.Show(exception.Message, exception.GetType().ToString(), AdonisUI.Controls.MessageBoxButton.OK, AdonisUI.Controls.MessageBoxImage.Error);
                        }
                    }

UranusDarkness avatar May 15 '22 21:05 UranusDarkness

It seems like it closes the application because I don't have an active window at that moment, since I'm using them in App.xaml. Is there a way to do so?

UranusDarkness avatar May 16 '22 09:05 UranusDarkness

New update: by debugging several times, I discovered that when it calls autoUpdateWindow.Show(), it raises the OnExit event of the App.xaml Still looking for a way to fix this tho

UranusDarkness avatar May 16 '22 19:05 UranusDarkness

I'm not sure this is specific to AdonisUI. This can happen when opening/closing a dialog when you don't have a main window open. Your best bet would be to enable explicit shutdown using the Application.Shutdown property: https://docs.microsoft.com/en-us/dotnet/api/system.windows.shutdownmode?view=windowsdesktop-6.0#system-windows-shutdownmode-onexplicitshutdown

fabraham-plexus avatar Jul 05 '22 18:07 fabraham-plexus