简体   繁体   English

Xamarin表单用于视图的TemplateSelector

[英]Xamarin Forms TemplateSelector for View

I would like to use a TemplateSelector to select a View. 我想使用TemplateSelector选择一个视图。 Not for ListViewItems, like every example out there shows, but with a "normal" View. 像上面的每个示例一样,不是ListViewItems,而是具有“普通”视图。 So i tried TemplatedView , ContentPresenter and ContentView . 所以我尝试了TemplatedViewContentPresenterContentView But non of them is able to take a TemplateSelector. 但是他们都不能够使用TemplateSelector。

Is there something i have missed? 有什么我想念的吗? Or how can i work around that? 或者我该如何解决?

EDIT: I have a TemplateSelector, just like described here . 编辑:我有一个TemplateSelector,就像这里描述的。 Now i want to add this Selector to some kind of ViewElement. 现在,我想将此选择器添加到某种ViewElement中。 Thats what i tried: 那就是我尝试过的:

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

or 要么

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

But nothing works, it always says "Invalid resource type" 但是没有任何效果,它总是显示“无效的资源类型”

EDIT2: 编辑2:

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

Have you tried following this guide of Xamarin? 您是否尝试过遵循Xamarin的指南? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/ 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 https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/triggers/#Data_Triggers不确定这是否是您寻找的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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