diff --git a/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopUpHandler.windows.cs b/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopUpHandler.windows.cs
index 0ea284563..ce3790e45 100644
--- a/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopUpHandler.windows.cs
+++ b/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopUpHandler.windows.cs
@@ -122,6 +122,7 @@ protected override void DisconnectHandler(Popup platformView)
{
MauiContext.GetPlatformWindow().SizeChanged -= OnSizeChanged;
}
+ DetachSwipeControlEvent(platformView);
}
///
@@ -140,6 +141,7 @@ protected override void ConnectHandler(Popup platformView)
{
MauiContext.GetPlatformWindow().SizeChanged += OnSizeChanged;
}
+ AttachSwipeControlEvent(platformView);
base.ConnectHandler(platformView);
}
@@ -168,4 +170,60 @@ void OnSizeChanged(object? sender, WindowSizeChangedEventArgs e)
PopupExtensions.SetLayout(PlatformView, VirtualView, MauiContext);
}
}
+
+ void AttachSwipeControlEvent(Popup platformView)
+ {
+ if (platformView.Child is FrameworkElement frameworkElement)
+ {
+ if (frameworkElement is SwipeControl)
+ {
+ SwipeControl swipeControl = (SwipeControl)frameworkElement;
+ swipeControl.Loaded += OnLoadedSwipeControl;
+ }
+ else
+ {
+ var swipeControls = frameworkElement.GetChildren();
+ foreach (SwipeControl? swipeControl in swipeControls)
+ {
+ if (swipeControl is not null)
+ {
+ swipeControl.Loaded += OnLoadedSwipeControl;
+ }
+ }
+ }
+ }
+ }
+
+ void DetachSwipeControlEvent(Popup platformView)
+ {
+ if (platformView.Child is FrameworkElement frameworkElement)
+ {
+ if (frameworkElement is SwipeControl)
+ {
+ SwipeControl swipeControl = (SwipeControl)frameworkElement;
+ swipeControl.Loaded -= OnLoadedSwipeControl;
+ }
+ else
+ {
+ var swipeControls = frameworkElement.GetChildren();
+ foreach (SwipeControl? swipeControl in swipeControls)
+ {
+ if (swipeControl is not null)
+ {
+ swipeControl.Loaded -= OnLoadedSwipeControl;
+ }
+ }
+ }
+ }
+ }
+
+ void OnLoadedSwipeControl(object? sender, RoutedEventArgs e)
+ {
+ if (VirtualView is not null)
+ {
+ PopupExtensions.SetSize(PlatformView, VirtualView, MauiContext);
+ PopupExtensions.SetLayout(PlatformView, VirtualView, MauiContext);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs b/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs
index 19b9ec17c..c16fadcfe 100644
--- a/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs
+++ b/src/CommunityToolkit.Maui.Core/Views/Popup/PopupExtensions.windows.cs
@@ -58,6 +58,33 @@ public static void ConfigureControl(this Popup mauiPopup, IPopup popup, IMauiCon
mauiPopup.SetLayout(popup, mauiContext);
}
+ static bool CanMeasureContent(Popup mauiPopup)
+ {
+ if (mauiPopup.Child is FrameworkElement frameworkElement)
+ {
+ if (frameworkElement is SwipeControl)
+ {
+ SwipeControl swipeControl = (SwipeControl)frameworkElement;
+ if (!swipeControl.IsLoaded)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ var swipeControls = frameworkElement.GetChildren();
+ foreach (SwipeControl? swipeControl in swipeControls)
+ {
+ if (swipeControl is not null && !swipeControl.IsLoaded)
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
///
/// Method to update the popup size based on the .
///
@@ -79,7 +106,14 @@ public static void SetSize(this Popup mauiPopup, IPopup popup, IMauiContext? mau
{
if (double.IsNaN(popup.Content.Width) || (double.IsNaN(popup.Content.Height)))
{
- currentSize = popup.Content.Measure(double.IsNaN(popup.Content.Width) ? popupParent.Bounds.Width : popup.Content.Width, double.IsNaN(popup.Content.Height) ? popupParent.Bounds.Height : popup.Content.Height);
+ if (CanMeasureContent(mauiPopup))
+ {
+ currentSize = popup.Content.Measure(double.IsNaN(popup.Content.Width) ? popupParent.Bounds.Width : popup.Content.Width, double.IsNaN(popup.Content.Height) ? popupParent.Bounds.Height : popup.Content.Height);
+ }
+ else
+ {
+ return;
+ }
if (double.IsNaN(popup.Content.Width))
{
@@ -129,7 +163,16 @@ public static void SetLayout(this Popup mauiPopup, IPopup popup, IMauiContext? m
ArgumentNullException.ThrowIfNull(popup.Content);
var popupParent = mauiContext.GetPlatformWindow();
- popup.Content.Measure(double.PositiveInfinity, double.PositiveInfinity);
+
+ if (CanMeasureContent(mauiPopup))
+ {
+ popup.Content.Measure(double.PositiveInfinity, double.PositiveInfinity);
+ }
+ else
+ {
+ return;
+ }
+
var contentSize = popup.Content.ToPlatform(mauiContext).DesiredSize;
var popupParentFrame = popupParent.Bounds;