Xamarin表单模板选择器

时间:2017-06-30 08:13:41

标签: c# xamarin xamarin.forms

我想使用TemplateSelector来选择View。不是ListViewItems,就像那里显示的每个例子一样,但是具有“普通”视图。所以我尝试了TemplatedViewContentPresenterContentView。但是没有它们能够采用TemplateSelector。

我有什么遗漏的吗?或者我该如何解决这个问题?

编辑: 我有一个TemplateSelector,就像描述here一样。现在我想将这个Selector添加到某种ViewElement中。那是我尝试过的:

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

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

但没有任何作用,它总是说“资源类型无效”

EDIT2:

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

1 个答案:

答案 0 :(得分:1)

您是否尝试过遵循Xamarin的指南? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

希望这对你有用。

编辑: 也许是替代解决方案: 有控制模板,但我不认为有一个选择器。你可以使用触发器吗? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/triggers/#Data_Triggers不确定这是否是你看的方式