xamarin 如何将VisualElementRenderer从XF转换为Maui处理程序

l5tcr1uw  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(135)

我需要将Xamarin Forms应用程序中的自定义呈现器转换为Maui处理程序。
因此,我有一个VisualElementRenderer,如下所示:

[assembly: ExportRenderer(typeof(CardsView), typeof(CardsViewRenderer))]
namespace CardView
{
    [Preserve(AllMembers = true)]
    public class CardsViewRenderer : VisualElementRenderer<CardsView>
    {
    }
}

其中CardsView是从AbsoluteLayout衍生而来。
现在,我尝试将其转换为Maui,但我无法找到一个VisualElementHandler来替换VisualElementRenderer。如果不是这样,我的处理程序将继承自什么,因为我没有一个PlatformView传递到我的ViewHandler,我不确定在这种情况下PlatformView将是什么。
到目前为止,这是我的想法

public partial class CardsViewHandler : ViewHandler<CardsView,??Not sure??>

谢谢你的帮助!

xxb16uws

xxb16uws1#

我已经检查了源代码,发现没有AbsoluteLayout的处理程序。但是AbsoluteLayout是从Layout继承的,Layout有一个LayoutHandler
当在Maui中创建Layout的示例时,LayoutHandler将返回ViewGroup(针对android)和UIView(针对ios)。因此,您可以尝试使用以下第一行代码(针对ios)和第二行代码(针对android)。

public partial class CardsViewHandler : ViewHandler<CardsView,LayoutView>
  //LayoutView is inherited from the MauiView which is inherited from the UIKit.UIView
public partial class CardsViewHandler : ViewHandler<CardsView,LayoutGroup>
  //LayoutGroup is inherited from Android.Views.ViewGroup

此外,还可以根据this link在maui中使用自定义渲染器。

相关问题