[英]Xamarin Forms TemplateSelector for View
我想使用TemplateSelector選擇一個視圖。 像上面的每個示例一樣,不是ListViewItems,而是具有“普通”視圖。 所以我嘗試了TemplatedView
, ContentPresenter
和ContentView
。 但是他們都不能夠使用TemplateSelector。
有什么我想念的嗎? 或者我該如何解決?
編輯:我有一個TemplateSelector,就像這里描述的。 現在,我想將此選擇器添加到某種ViewElement中。 那就是我嘗試過的:
<TemplatedView ControlTemplate="{StaticResource ViewItemTemplateSelector}"/>
要么
<ContentPresenter Content="{StaticResource ViewItemTemplateSelector}"/>
但是沒有任何效果,它總是顯示“無效的資源類型”
編輯2:
<ResourceDictionary MergedWith="dataTemplates:DataTemplates">
<helper:ViewItemTemplateSelector x:Key="ViewItemTemplateSelector"
TextDataTemplate="{StaticResource TextDataTemplate}"/>
您是否嘗試過遵循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不確定這是否是您尋找的方式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.