diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs index 8e225bc079cc..4db50de8ea3e 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs @@ -12,6 +12,7 @@ public partial class ImageButtonHandler : ViewHandler PointerEventHandler? _pointerPressedHandler; PointerEventHandler? _pointerReleasedHandler; + bool _isPressed; protected override Button CreatePlatformView() { @@ -44,6 +45,7 @@ protected override void ConnectHandler(Button platformView) } platformView.Click += OnClick; + platformView.Unloaded += OnUnloaded; platformView.AddHandler(UIElement.PointerPressedEvent, _pointerPressedHandler, true); platformView.AddHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler, true); @@ -59,6 +61,7 @@ protected override void DisconnectHandler(Button platformView) } platformView.Click -= OnClick; + platformView.Unloaded -= OnUnloaded; platformView.RemoveHandler(UIElement.PointerPressedEvent, _pointerPressedHandler); platformView.RemoveHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler); @@ -104,14 +107,25 @@ void OnClick(object sender, RoutedEventArgs e) void OnPointerPressed(object sender, PointerRoutedEventArgs e) { + _isPressed = true; VirtualView?.Pressed(); } void OnPointerReleased(object sender, PointerRoutedEventArgs e) { + _isPressed = false; VirtualView?.Released(); } + void OnUnloaded(object sender, RoutedEventArgs e) + { + // WinUI will not raise the PointerReleased event if the pointer is pressed and then unloaded + if (_isPressed) + { + VirtualView?.Released(); + } + } + void OnImageOpened(object sender, RoutedEventArgs routedEventArgs) { VirtualView?.UpdateIsLoading(false);