Hello,
Welcome to Microsoft Q&A!
As a workaround you can use create a DataTemplateSelector , select the template according to the property defined in model .
Model and DataTemplateSelector
public class Model
{
public bool isListView { get; set; }
}
public class MyTemplateSelector : DataTemplateSelector
{
public DataTemplate ListViewTemplate { get; set; }
public DataTemplate CollectionViewTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
return ((Model)item).isListView ? ListViewTemplate : CollectionViewTemplate;
}
}
DataTemplate in App
<Application.Resources>
<ResourceDictionary>
<DataTemplate x:Key="ListViewTemplate">
<ViewCell>
<StackLayout>
<Label />
</StackLayout>
</ViewCell>
</DataTemplate>
<DataTemplate x:Key="CollectionViewTemplate">
<StackLayout>
<Label />
</StackLayout>
</DataTemplate>
<local:MyTemplateSelector x:Key="MyTemplateSelector"
ListViewTemplate="{StaticResource ListViewTemplate}"
CollectionViewTemplate="{StaticResource CollectionViewTemplate}" />
</ResourceDictionary>
</Application.Resources>
Usage
<ListView ItemTemplate="{StaticResource MyTemplateSelector}" />
<CollectionView ItemTemplate="{StaticResource MyTemplateSelector}" />
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.