XAML:
<ContentPage.Resources> <ResourceDictionary> <DataTemplate x:Key="default"> .. </DataTemplate>
<DataTemplate x:Key="specific"> .. </DataTemplate> </ResourceDictionary> </ContentPage.Resources> <ContentPage.Content> <StackLayout> <Label Text="High performance Mobiles" FontSize="Medium" FontAttributes="Bold"/> <Label Text="Choose a Device to place order" FontAttributes="None" FontSize="Micro"/> <combobox:SfComboBox DataSource="{Binding Data}" x:Name="comboBox" DisplayMemberPath="dsproduct"> <combobox:SfComboBox.ItemTemplate> <local:MyDataTemplateSelector DefaultTemplate="{StaticResource default}" SpecificDataTemplate="{StaticResource specific}"/> </combobox:SfComboBox.ItemTemplate> </combobox:SfComboBox> </StackLayout> </ContentPage.Content> </ContentPage> C#
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { var message = item as Product; return message.amount <= 0 ? DefaultTemplate : SpecificDataTemplate; } |