diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 00761dfce8..5b9eebb9cb 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -100,14 +100,17 @@ namespace Avalonia.X11 int defaultWidth = 300, defaultHeight = 200; - if (!_popup) + if (!_popup && Screen != null) { var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity) .FirstOrDefault(m => m.Bounds.Contains(Position)); - // Emulate Window 7+'s default window size behavior. - defaultWidth = (int)(monitor.WorkingArea.Width * 0.75d); - defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d); + if (monitor != null) + { + // Emulate Window 7+'s default window size behavior. + defaultWidth = (int)(monitor.WorkingArea.Width * 0.75d); + defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d); + } } _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0,