<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:XamlSamples;assembly=XamlSamples"
             x:Class="XamlSamples.ListViewDemoPage"
             Title="ListView Demo Page">

  <ContentPage.Resources>
    <ResourceDictionary>
      <OnPlatform x:Key="boxSize"
                  x:TypeArguments="x:Double"
                  iOS="50"
                  Android="50"
                  WinPhone="75" />

      <!-- This is only an issue on the iPhone; Android and 
           WinPhone auto size the row height to the contents. -->
      <OnPlatform x:Key="rowHeight" 
                  x:TypeArguments="x:Int32"
                  iOS="60"
                  Android="60"
                  WinPhone="85" />

      <local:DoubleToIntConverter x:Key="intConverter" />
      
    </ResourceDictionary>
  </ContentPage.Resources>

  <ListView ItemsSource="{x:Static local:NamedColor.All}"
            RowHeight="{StaticResource rowHeight}">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <ViewCell.View>
            <StackLayout Padding="5, 5, 0, 5"
                         Orientation="Horizontal"
                         Spacing="15">
              
              <BoxView WidthRequest="{StaticResource boxSize}"
                       HeightRequest="{StaticResource boxSize}"
                       Color="{Binding Color}" />

              <StackLayout Padding="5, 0, 0, 0"
                           VerticalOptions="Center">
                
                <Label Text="{Binding FriendlyName}"
                       Font="Bold, Medium" />

                <StackLayout Orientation="Horizontal"
                             Spacing="0">
                  <Label Text="{Binding Color.R,
                                   Converter={StaticResource intConverter},
                                   ConverterParameter=255,
                                   StringFormat='R={0:X2}'}" />
                  <Label Text="{Binding Color.G,
                                   Converter={StaticResource intConverter},
                                   ConverterParameter=255,
                                   StringFormat=', G={0:X2}'}" />
                  <Label Text="{Binding Color.B,
                                   Converter={StaticResource intConverter},
                                   ConverterParameter=255,
                                   StringFormat=', B={0:X2}'}" />
                </StackLayout>
              </StackLayout>
            </StackLayout>
          </ViewCell.View>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</ContentPage>