mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-05-19 22:16:25 -04:00
Fix Primary Screen NRE (#1420)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user