benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.75k stars 146 forks source link

MessageBox result closes application #189

Open UranusDarkness opened 2 years ago

UranusDarkness commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

fabraham-plexus commented 2 years ago

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