SwipeCardView
SwipeCardView copied to clipboard
Support for multiple ItemTemplate DataTemplates
Is there any support for multiple ItemTemplate, and then use the DataTemplateSelector to choose which DataTemplate to display.
I want to insert adverts every 5 cards and that has a different layout.
So define
ItemTemplate="{StaticResource EmptyViewTemplate}"
define your DataTemplate in the Resouces
and then reference a DataTemplateSelector. This works fine for a CarouselView, but errors with Failed on LoadTemplate for SwipeCardView - can you fix. I am pushed for time, so if you can either address this or let me know a work around I would really appreciate it.
<local:ResultTemplateSelector x:Key="ResultItemTemplateSelector"
AdvertViewTemplate="{StaticResource AdvertViewTemplate}"
DonorViewTemplate="{StaticResource DonorViewTemplate}"
EmptyViewTemplate="{StaticResource EmptyViewTemplate}" />
Hi @adha-admin, Unfortunately, DataTemplateSelectors are not supported at the moment. I just pushed to master sample page (TemplateSelectorPage) that confirms your observation.
I quickly tried drafting a change for OnItemTemplatePropertyChanged, but it seems that it doesn't work:
DataTemplate dataTemplate;
if (swipeCardView.ItemTemplate is DataTemplateSelector)
{
dataTemplate = (swipeCardView.ItemTemplate as DataTemplateSelector).SelectTemplate(swipeCardView._cards[i].BindingContext, null);
}
else
{
dataTemplate = swipeCardView.ItemTemplate;
}
var content = dataTemplate.CreateContent();
If you would like, you could debug this code and check what's going on, but most likely this one will have to wait for a major refactoring in order to be resolved.
Thanks Mark, That was my observation also - The problem is that the view of the "next" view is already built by the time the swipe has happened. I Ended up using the flags I was using in the DataTemplateSelectors for the sections i wanted to show or not, and that works ok, so i am fine for now.
Having the "EmptyView" would still be good to have though (I had to fudge a dummy record to show when the list was complete as per issue: https://github.com/markolazic88/SwipeCardView/issues/8)