diff --git a/src/Avalonia.Controls/Screens.cs b/src/Avalonia.Controls/Screens.cs index 22f9c0832a..a9f52315f9 100644 --- a/src/Avalonia.Controls/Screens.cs +++ b/src/Avalonia.Controls/Screens.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Avalonia.Platform; -using Avalonia.VisualTree; #nullable enable @@ -43,6 +42,17 @@ namespace Avalonia.Controls return _iScreenImpl.ScreenFromRect(bounds); } + public Screen? ScreenFromWindow(WindowBase window) + { + if (window.PlatformImpl is null) + { + throw new ObjectDisposedException("Window platform implementation was already disposed."); + } + + return _iScreenImpl.ScreenFromWindow(window.PlatformImpl); + } + + [Obsolete("Use ScreenFromWindow(WindowBase) overload.")] public Screen? ScreenFromWindow(IWindowBaseImpl window) { return _iScreenImpl.ScreenFromWindow(window); diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 48edb81b16..66cce89b9d 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -713,7 +713,7 @@ namespace Avalonia.Controls Owner = owner; owner?.AddChild(this, false); - SetWindowStartupLocation(owner?.PlatformImpl); + SetWindowStartupLocation(owner); PlatformImpl?.Show(ShowActivated, false); Renderer.Start(); @@ -789,7 +789,7 @@ namespace Avalonia.Controls Owner = owner; owner.AddChild(this, true); - SetWindowStartupLocation(owner.PlatformImpl); + SetWindowStartupLocation(owner); PlatformImpl?.Show(ShowActivated, true); @@ -870,7 +870,7 @@ namespace Avalonia.Controls } } - private void SetWindowStartupLocation(IWindowBaseImpl? owner = null) + private void SetWindowStartupLocation(Window? owner = null) { var startupLocation = WindowStartupLocation;