Files
marketally.mopups/Mopups/Mopups.Maui/Platforms/Windows/Handler/PopupPageHandler.cs
David Friedel bf68a5f09a Fix VirtualView null exceptions and popup removal race condition
- Fix RemoveAsync race condition: close popup before disconnecting handler
- Add null-safe VirtualView access with try-catch on all platforms
- Properly unsubscribe SizeChanged event in PopupPageHandler
- Fix Android Window type ambiguity with fully qualified name
- Fix README path in csproj

The root cause was layout events firing during popup removal while
the handler was being disconnected. Now we close the popup first
to stop events, then clean up.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 23:14:34 +00:00

46 lines
1.2 KiB
C#

using Microsoft.Maui.Handlers;
using Microsoft.Maui.Layouts;
using Microsoft.Maui.Platform;
namespace Mopups.Platforms.Windows
{
public class PopupPageHandler : PageHandler
{
private Microsoft.UI.Xaml.SizeChangedEventHandler? _sizeChangedHandler;
public PopupPageHandler()
{
}
protected override void ConnectHandler(ContentPanel platformView)
{
base.ConnectHandler(platformView);
_sizeChangedHandler = (_, e) =>
{
try
{
VirtualView?.ComputeDesiredSize(e.NewSize.Width, e.NewSize.Height);
}
catch (InvalidOperationException) { }
};
PlatformView.SizeChanged += _sizeChangedHandler;
}
protected override void DisconnectHandler(ContentPanel platformView)
{
if (_sizeChangedHandler != null)
{
platformView.SizeChanged -= _sizeChangedHandler;
_sizeChangedHandler = null;
}
base.DisconnectHandler(platformView);
}
protected override ContentPanel CreatePlatformView()
{
return new PopupPageRenderer(this);
}
}
}