From ff3ac2d6fd23291e940ccb7231814f074f34b6d5 Mon Sep 17 00:00:00 2001 From: Mbucari Date: Fri, 11 Aug 2023 09:04:05 -0600 Subject: [PATCH] Fix MessageBox crash when UI has no Screens (#708) --- Source/LibationAvalonia/MessageBox.cs | 7 +++++-- Source/LibationAvalonia/Views/MainWindow.axaml.cs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/LibationAvalonia/MessageBox.cs b/Source/LibationAvalonia/MessageBox.cs index b5468893..880c3269 100644 --- a/Source/LibationAvalonia/MessageBox.cs +++ b/Source/LibationAvalonia/MessageBox.cs @@ -177,9 +177,12 @@ Libation. tbx.MinWidth = vm.TextBlockMinWidth; tbx.Text = message; - var thisScreen = owner.Screens.ScreenFromVisual(owner); + + var thisScreen = owner.Screens?.ScreenFromVisual(owner); - var maxSize = new Size(0.20 * thisScreen.Bounds.Width, 0.9 * thisScreen.Bounds.Height - 55); + var maxSize + = thisScreen is null ? owner.ClientSize + : new Size(0.20 * thisScreen.Bounds.Width, 0.9 * thisScreen.Bounds.Height - 55); var desiredMax = new Size(maxSize.Width, maxSize.Height); diff --git a/Source/LibationAvalonia/Views/MainWindow.axaml.cs b/Source/LibationAvalonia/Views/MainWindow.axaml.cs index c708258c..a33d95df 100644 --- a/Source/LibationAvalonia/Views/MainWindow.axaml.cs +++ b/Source/LibationAvalonia/Views/MainWindow.axaml.cs @@ -21,7 +21,7 @@ namespace LibationAvalonia.Views InitializeComponent(); Configure_Upgrade(); - Loaded += MainWindow_Loaded; + Opened += MainWindow_Opened; Closing += MainWindow_Closing; LibraryLoaded += MainWindow_LibraryLoaded; @@ -35,7 +35,7 @@ namespace LibationAvalonia.Views } } - private async void MainWindow_Loaded(object sender, EventArgs e) + private async void MainWindow_Opened(object sender, EventArgs e) { if (Configuration.Instance.FirstLaunch) {