2

I have a base class, which looks like the following

public class DialogSelectionItem<Tobject> : ViewCell

Now I want to attach a custom renderer to it:

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

The problem is

The type or namespace name 'Tobject' could not be found (are you missing a using directive or an assembly reference?)

I can use object instead, but then the custom renderer is never called.

Is there an option to get the correct type or use the generic? How should I define the ExportRenderer?

testing
  • 19,681
  • 50
  • 236
  • 417
  • How are you using your custom ViewCell in XAML? – VahidShir Jun 19 '19 at 16:18
  • I just tested that but with a generic Label and used `typeof(CustomLabel)` and it was called successfully. – VahidShir Jun 19 '19 at 16:21
  • @Vahid: I'm calling it like so `ItemTemplate = new DataTemplate(typeof(DialogSelectionItem))`. In my case the app seems to be depending on the type. And `object` is none of my *valid* types. At least as I see as explanation for the difference in behavior. – testing Jun 19 '19 at 16:27

1 Answers1

1

OK the solution is posted here.

Base class:

public class DialogSelectionItem : ViewCell
{
    // nothing
}

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

View renderer:

[assembly: ExportRenderer(typeof(SomeApp.CustomRenderers.DialogSelectionItem), typeof(SomeApp.iOS.CustomRenderers.DialogSelectionItemRenderer))]
namespace SomeApp.iOS.CustomRenderers
{
    public class DialogSelectionItemRenderer : ViewCellRenderer
    {
        // some customizations
    }
}
testing
  • 19,681
  • 50
  • 236
  • 417