44
55using System ;
66using System . Linq ;
7- using System . Threading ;
87using Windows . Foundation ;
98using Windows . Graphics . Display ;
109using Windows . UI . Text ;
@@ -21,8 +20,13 @@ public partial class RichSuggestBox
2120 {
2221 private static bool IsElementOnScreen ( FrameworkElement element , double offsetX = 0 , double offsetY = 0 )
2322 {
24- var toWindow = element . TransformToVisual ( Window . Current . Content ) ;
25- var windowBounds = ApplicationView . GetForCurrentView ( ) . VisibleBounds ;
23+ if ( Window . Current == null )
24+ {
25+ return ! ControlHelpers . IsXamlRootAvailable || element . XamlRoot . IsHostVisible ;
26+ }
27+
28+ var toWindow = element . TransformToVisual ( null ) ;
29+ var windowBounds = Window . Current . Bounds ;
2630 var elementBounds = new Rect ( offsetX , offsetY , element . ActualWidth , element . ActualHeight ) ;
2731 elementBounds = toWindow . TransformBounds ( elementBounds ) ;
2832 elementBounds . X += windowBounds . X ;
@@ -35,8 +39,10 @@ private static bool IsElementOnScreen(FrameworkElement element, double offsetX =
3539
3640 private static bool IsElementInsideWindow ( FrameworkElement element , double offsetX = 0 , double offsetY = 0 )
3741 {
38- var toWindow = element . TransformToVisual ( Window . Current . Content ) ;
39- var windowBounds = ApplicationView . GetForCurrentView ( ) . VisibleBounds ;
42+ var toWindow = element . TransformToVisual ( null ) ;
43+ var windowBounds = ControlHelpers . IsXamlRootAvailable
44+ ? element . XamlRoot . Size . ToRect ( )
45+ : ApplicationView . GetForCurrentView ( ) . VisibleBounds ;
4046 windowBounds = new Rect ( 0 , 0 , windowBounds . Width , windowBounds . Height ) ;
4147 var elementBounds = new Rect ( offsetX , offsetY , element . ActualWidth , element . ActualHeight ) ;
4248 elementBounds = toWindow . TransformBounds ( elementBounds ) ;
0 commit comments