4
4
5
5
using System ;
6
6
using System . Linq ;
7
- using System . Threading ;
8
7
using Windows . Foundation ;
9
8
using Windows . Graphics . Display ;
10
9
using Windows . UI . Text ;
@@ -21,8 +20,13 @@ public partial class RichSuggestBox
21
20
{
22
21
private static bool IsElementOnScreen ( FrameworkElement element , double offsetX = 0 , double offsetY = 0 )
23
22
{
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 ;
26
30
var elementBounds = new Rect ( offsetX , offsetY , element . ActualWidth , element . ActualHeight ) ;
27
31
elementBounds = toWindow . TransformBounds ( elementBounds ) ;
28
32
elementBounds . X += windowBounds . X ;
@@ -35,8 +39,10 @@ private static bool IsElementOnScreen(FrameworkElement element, double offsetX =
35
39
36
40
private static bool IsElementInsideWindow ( FrameworkElement element , double offsetX = 0 , double offsetY = 0 )
37
41
{
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 ;
40
46
windowBounds = new Rect ( 0 , 0 , windowBounds . Width , windowBounds . Height ) ;
41
47
var elementBounds = new Rect ( offsetX , offsetY , element . ActualWidth , element . ActualHeight ) ;
42
48
elementBounds = toWindow . TransformBounds ( elementBounds ) ;
0 commit comments