【发布时间】:2019-11-02 10:17:49
【问题描述】:
我有一个基类,如下所示
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?
【问题讨论】:
-
您如何在 XAML 中使用自定义 ViewCell?
-
我刚刚测试了它,但使用了通用标签并使用了
typeof(CustomLabel<object>),它被成功调用了。 -
@Vahid:我这样称呼它
ItemTemplate = new DataTemplate(typeof(DialogSelectionItem<Tobject>))。就我而言,该应用程序似乎取决于类型。object不是我的 valid 类型。至少在我看来,这是对行为差异的解释。
标签: c# generics xamarin.forms custom-renderer