如何创建Xamarin.Forms自定义渲染器,其中渲染器基类使用泛型?

时间:2019-06-19 15:51:30

标签: c# generics xamarin.forms custom-renderer

我有一个基类,看起来像下面的

public class DialogSelectionItem<Tobject> : ViewCell

现在,我要向其附加一个自定义渲染器:

[assembly: ExportRenderer(typeof(SomeApp.CustomRenderers.DialogSelectionItem<Tobject>), typeof(SomeApp.iOS.CustomRenderers.DialogSelectionItemRenderer))]
namespace SomeApp.iOS.CustomRenderers
{
    public class DialogSelectionItemRenderer : ViewCellRenderer
    {
        // some customizations
    }
}

问题是

  

找不到类型或名称空间名称'Tobject'(您是否缺少using指令或程序集引用?)

我可以改用object,但是从不调用自定义渲染器。

是否可以选择正确的类型或使用泛型?我应该如何定义ExportRenderer

1 个答案:

答案 0 :(得分:0)

好,解决方案已发布here

基类:

if not defined

查看渲染器:

public class DialogSelectionItem : ViewCell
{
    // nothing
}

public class DialogSelectionItem<Tobject> : DialogSelectionItem
{
    // do something
}