M.D.
M.D.

Reputation: 273

Xamarin Forms TemplateSelector for View

I would like to use a TemplateSelector to select a View. Not for ListViewItems, like every example out there shows, but with a "normal" View. So i tried TemplatedView, ContentPresenter and ContentView. But non of them is able to take a TemplateSelector.

Is there something i have missed? Or how can i work around that?

EDIT: I have a TemplateSelector, just like described here. Now i want to add this Selector to some kind of ViewElement. Thats what i tried:

<TemplatedView ControlTemplate="{StaticResource ViewItemTemplateSelector}"/>

or

<ContentPresenter Content="{StaticResource ViewItemTemplateSelector}"/>

But nothing works, it always says "Invalid resource type"

EDIT2:

<ResourceDictionary MergedWith="dataTemplates:DataTemplates">
        <helper:ViewItemTemplateSelector x:Key="ViewItemTemplateSelector" 
                                         TextDataTemplate="{StaticResource TextDataTemplate}"/>

Upvotes: 2

Views: 2933

Answers (1)

Jordy Dieltjens
Jordy Dieltjens

Reputation: 1538

Have you tried following this guide of Xamarin? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

Hope this works out for you.

EDIT: Perhaps an alternative solution: There are control templates but i don't think there is a selector for it. You could maybe use triggers for it? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/triggers/#Data_Triggers not sure if this is way you looking

Upvotes: 1

Related Questions