I am in the process of making a custom horizontally scrollable ListView type control, I have come across an issue which I can't explain, and I'm not 100% sure that the issue is even with my code, unless I have misunderstood something.
I have distilled the issue into the simplest form I can, available at https://github.com/sparkeh9/XamarinFormsListViewIssue.
So, I have a HorizontalListView control utilising a very simple data template selector (no logic, returns a single data template)
See Template Selector screenshot
My issue is, when I use a template selector, when calling ItemTemplateSelector.CreateContent()
in order to start generating UI controls based on the template, it throws an exception See exception screenshot which claims that the LoadTemplate property should not be null. I have looked at the base classes and found that this property is a Func<object>
which is private, and can only be set from outside by calling a specific constructor.
If I specify a literal item template in the XAML, everything works as expected, such as:
<controls:HorizontalListView.ItemTemplate>
<DataTemplate>
<Label Text="test"></Label>
</DataTemplate>
</controls:HorizontalListView.ItemTemplate>
EDIT: Answered my own question