Fix Primary Screen NRE (#1420)

This commit is contained in:
MBucari
2025-11-11 03:21:20 -07:00
parent d16eeea56b
commit a3d181b2ec
2 changed files with 7 additions and 5 deletions

View File

@@ -1,13 +1,15 @@
using Avalonia;
using Avalonia.Controls;
using System;
using System.Linq;
#nullable enable
namespace LibationAvalonia.Dialogs
{
public partial class DescriptionDisplayDialog : Window
{
public Point SpawnLocation { get; set; }
public string DescriptionText { get; init; }
public string? DescriptionText { get; init; }
public DescriptionDisplayDialog()
{
InitializeComponent();
@@ -17,15 +19,15 @@ namespace LibationAvalonia.Dialogs
Opened += DescriptionDisplay_Opened;
}
private void DescriptionDisplay_Opened(object sender, EventArgs e)
private void DescriptionDisplay_Opened(object? sender, EventArgs e)
{
DescriptionTextBox.Focus();
}
private void DescriptionDisplay_Activated(object sender, EventArgs e)
private void DescriptionDisplay_Activated(object? sender, EventArgs e)
{
DataContext = this;
var workingHeight = this.Screens.Primary.WorkingArea.Height;
var workingHeight = (Screens.ScreenFromTopLevel(this) ?? Screens.Primary ?? Screens.All.FirstOrDefault())?.WorkingArea.Height ?? 1080;
DescriptionTextBox.Measure(new Size(DescriptionTextBox.MinWidth, workingHeight * 0.8));
this.Width = DescriptionTextBox.DesiredSize.Width;

View File

@@ -41,7 +41,7 @@ namespace LibationAvalonia
savedState.Width = (int)form.Width;
savedState.Height = (int)form.Height;
}
if (form.Screens.Primary is Screen primaryScreen)
if ((form.Screens.Primary ?? form.Screens.All.FirstOrDefault()) is Screen primaryScreen)
{
// Fit to the current screen size in case the screen resolution changed since the size was last persisted
if (savedState.Width > primaryScreen.WorkingArea.Width)