xamarin 社区工具包 toucheffect maui 的替代品

问题描述 投票:0回答:1

有人知道是否有使用 DotNet MAUI 长触摸的解决方法? 在我使用 Xamarin 构建的遗留应用程序中,我使用的是 xct:TouchEffect.LongPressCommand。

据我所知,MAUI 社区工具包中有一个 wip,但目前不可用。

也许使用 EventToCommandBehaviour? 如果我使用这个,活动的名称是什么?

有没有办法用 propertyMapper 和 CommandMapper 来扩展例如 ImageHandler 来实现这个目标? 也许有人有其他想法? 预先感谢您的任何建议😇

touch maui touch-event
1个回答
0
投票

如果能用 .Net MAUI 实现长触摸效果那就太棒了,Github 上有一个提案将其包含在 MAUI 社区工具包中。根据线程更新,很快就会实现。

作为替代解决方法,您可以尝试找到 MAUI 控件的处理程序,然后获取

handler.PlatformView
,这是一个本机控件。之后,您可以调用原生控件方法,并订阅原生控件事件,例如手势事件,请参阅使用处理程序自定义.NET MAUI控件并参考以下代码:

用mapper自定义控件(对Image控件有效):

 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  
});  

在各平台实现长按事件:

#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)  
    {  
        //raise longpress event 
    }  
#endif  
#if ANDROID  
    private void PlatformView_LongClick(object sender, Android.Views.View.LongClickEventArgs e)  
    {  
        //raise longpress event 
    }  
#endif  

参考链接:https://learn.microsoft.com/en-us/answers/questions/900859/long-press-in-net-maui

© www.soinside.com 2019 - 2024. All rights reserved.