简体   繁体   中英

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}"/>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM