Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple ItemTemplate DataTemplates #26

Open
adha-admin opened this issue Jul 19, 2020 · 2 comments
Open

Support for multiple ItemTemplate DataTemplates #26

adha-admin opened this issue Jul 19, 2020 · 2 comments

Comments

@adha-admin
Copy link

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}"  />
@markolazic88
Copy link
Owner

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.

@adha-admin
Copy link
Author

adha-admin commented Jul 21, 2020

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: #8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants