Skip to content

Commit 3d03ce7

Browse files
committed
dont use ApplicationView when XamlRoot is available
1 parent 7b7974b commit 3d03ce7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/RichSuggestBox/RichSuggestBoxPage.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public RichSuggestBoxPage()
9898

9999
public void OnXamlRendered(FrameworkElement control)
100100
{
101-
102101
if (this._rsb != null)
103102
{
104103
this._rsb.SuggestionChosen -= this.SuggestingBox_OnSuggestionChosen;

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System;
66
using System.Linq;
7-
using System.Threading;
87
using Windows.Foundation;
98
using Windows.Graphics.Display;
109
using 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

Comments
 (0)