Implementing the DataTemplateSelector in XAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:AlternateRowColorSample" x:Class="AlternateRowColorSample.MainPage"> | |
<ContentPage.Resources> | |
<ResourceDictionary> | |
<DataTemplate x:Key="evenTemplate"> | |
<ViewCell> | |
<Grid BackgroundColor="White"> | |
<Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center" /> | |
</Grid> | |
</ViewCell> | |
</DataTemplate> | |
<DataTemplate x:Key="unevenTemplate"> | |
<ViewCell> | |
<Grid BackgroundColor="LightGray"> | |
<Label Text="{Binding .}" TextColor="White" HorizontalOptions="Center" VerticalOptions="Center" /> | |
</Grid> | |
</ViewCell> | |
</DataTemplate> | |
<local:AlternateColorDataTemplateSelector x:Key="alternateColorDataTemplateSelector" | |
EvenTemplate="{StaticResource evenTemplate}" | |
UnevenTemplate="{StaticResource unevenTemplate}" /> | |
</ResourceDictionary> | |
</ContentPage.Resources> | |
<ListView ItemTemplate="{StaticResource alternateColorDataTemplateSelector}" ItemsSource="{Binding Items}" /> | |
</ContentPage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment