Skip to content

Commit b4ac3eb

Browse files
committed
fix: Avoid null-ref, fallback to VisibleBounds is XamlRoot is null
1 parent 23fd35a commit b4ac3eb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Uno.UI/UI/Xaml/Controls/Popup/PopupPanel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ protected override Size MeasureOverride(Size availableSize)
6969
else
7070
{
7171
Rect visibleBounds;
72-
if (XamlRoot.VisualTree.ContentRoot.Type == ContentRootType.CoreWindow)
72+
if (XamlRoot is not { } xamlRoot || xamlRoot.VisualTree.ContentRoot.Type == ContentRootType.CoreWindow)
7373
{
7474
visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds;
7575
}
7676
else
7777
{
78-
visibleBounds = XamlRoot.Bounds;
78+
visibleBounds = xamlRoot.Bounds;
7979
}
8080
visibleBounds.Width = Math.Min(availableSize.Width, visibleBounds.Width);
8181
visibleBounds.Height = Math.Min(availableSize.Height, visibleBounds.Height);
@@ -165,14 +165,15 @@ protected override Size ArrangeOverride(Size finalSize)
165165
// Defer to the popup owner the responsibility to place the popup (e.g. ComboBox)
166166

167167
Rect visibleBounds;
168-
if (XamlRoot.VisualTree.ContentRoot.Type == ContentRootType.CoreWindow)
168+
if (XamlRoot is { } xamlRoot && xamlRoot.VisualTree.ContentRoot.Type != ContentRootType.CoreWindow)
169169
{
170-
visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds;
170+
visibleBounds = xamlRoot.Bounds;
171171
}
172172
else
173173
{
174-
visibleBounds = XamlRoot.Bounds;
174+
visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds;
175175
}
176+
176177
visibleBounds.Width = Math.Min(finalSize.Width, visibleBounds.Width);
177178
visibleBounds.Height = Math.Min(finalSize.Height, visibleBounds.Height);
178179

0 commit comments

Comments
 (0)