Open Sebastian1989101 opened 6 years ago
Would be great if @daniel-luberda would care more about the issues and problems of those controls.. But there is simply no option currently except for a self implementation.
@Sebastian1989101 I think you need to use FlowTemplateSelector
.
I just implemented the selector yesterday and it works fine.
public class NewsTemplateSelector : FlowTemplateSelector
{
protected override DataTemplate OnSelectTemplate(object item, int columnIndex, BindableObject container)
{
if (item is NewsListItemModel newsListItemModel)
{
switch (newsListItemModel.Type)
{
case NewsListItemModelType.Normal:
return new NewsItemTemplate();
case NewsListItemModelType.Header:
return new NewsHeaderTemplate();
default: throw new NotImplementedException($"{nameof(NewsTemplateSelector)} does not have a template for type: {newsListItemModel.Type}");
}
}
throw new NotImplementedException($"{nameof(NewsTemplateSelector)} did not receive a {nameof(NewsListItemModel)} item");
}
}
@c-lamont Nope dosn't work. Still the same mess. But as you can see above, I use a base type for my list and want a different template for a different type. Also I do not create new templates per entry as you did (because it creates memory leaks, see: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/ (because the FLV ist based on a normal LV)). So one of those must be the problem than.
I guess the difference is, that I use the same instance again you don't. But changing this is not an option due to the memory leak potential so it needs to get fixed. But because of the owner does not care about his projects, everyone with this issue needs to fix it on it's own (PR's are also not merged so yea...).
Sorry, didn't have much time recently to update this repo (it's just a side project, I do other things for a living ) :)
Could you make a repo? I can't reproduce it. I tested it on XF 3.0, so it might have been a Xamarin.Forms issue.
When using a DataTemplateSelector, the FlowListView Control seems to be randomly choose which template is used for which cell - even if it is 100% clear and correctly served by the template selector (same template instance for additional requests on the same item; not more than 8 on Android).
Here is my current template selector:
Item, Entry and Other are all Models on it's own and all implement a interface which is the type of my bounded list. But the FlowListView should not care about it anyway and just use the served template for the cell... currently it using it random on the first call (if the result list is a mixed result) and all other results using the same template for the same list index (even if the model on the slot changes it type due to a list modification). I use this for a whole App Search and I want to display each entry with it's own template.