Hello,
a long click could be useful in many places, so wherever it can be added.
Gird
and Frame
do not have Handler and cannot use custom renderer in the MAUI.
If you want to detect long click for other controls, you can invoke native control methods, and subscribe to native control events such as the gesture event in Handler.
For example, If I want to detect long click event for Image, we can implement in the Image handler.
Microsoft.Maui.Handlers.ImageHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if WINDOWS
handler.PlatformView.Holding += PlatformView_Holding;
#endif
#if ANDROID
handler.PlatformView.LongClick += PlatformView_LongClick;
#endif
#if IOS
handler.PlatformView.UserInteractionEnabled = true;
handler.PlatformView.AddGestureRecognizer(new UILongPressGestureRecognizer(HandleLongClick));
#endif
});
Long press event under each platform
#if WINDOWS
private void PlatformView_Holding(object sender, Microsoft.UI.Xaml.Input.HoldingRoutedEventArgs e)
{
//Touch can produce a Holding action, but mouse devices generally can't.
//see https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.holding?view=winrt-22621
}
#endif
#if IOS
private void HandleLongClick(UILongPressGestureRecognizer sender)
{
//do something
}
#endif
#if ANDROID
private void PlatformView_LongClick(object sender, Android.Views.View.LongClickEventArgs e)
{
// do something
}
#endif
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.