Skip to content

Commit 46bd862

Browse files
Provide better guards for UWP
1 parent 4e327ed commit 46bd862

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Input/RichSuggestBox/RichSuggestBox.Helpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using Windows.Foundation;
88
using Windows.Graphics.Display;
9+
using Windows.UI.Core;
910
using Windows.UI.Text;
1011
using Windows.UI.ViewManagement;
1112
using Windows.UI.Xaml;
@@ -26,7 +27,7 @@ private static bool IsElementOnScreen(FrameworkElement element, double offsetX =
2627
// https://github.com/microsoft/WindowsAppSDK/issues/114
2728
// https://github.com/microsoft/microsoft-ui-xaml/issues/4228
2829
// TODO: Remove when DisplayInformation.ScreenHeightInRawPixels alternative is available
29-
if (Window.Current == null)
30+
if (CoreWindow.GetForCurrentThread() == null)
3031
{
3132
return true;
3233
}
@@ -64,7 +65,7 @@ private static bool IsElementInsideWindow(FrameworkElement element, double offse
6465
elementBounds.Y += offsetY;
6566

6667
// Get size of window itself
67-
var windowBounds = ControlHelpers.IsXamlRootAvailable
68+
var windowBounds = ControlHelpers.IsXamlRootAvailable && element.XamlRoot != null
6869
? element.XamlRoot.Size.ToRect()
6970
: ApplicationView.GetForCurrentView().VisibleBounds.ToSize().ToRect(); // Normalize
7071

0 commit comments

Comments
 (0)