ListView

A view that displays a collection as a vertical list. The ListView automatically scrolls when the items can not all be displayed on one screen.

In XAML

<ListView ItemsSource="{StaticResource Countries}" />

The ListView is using a static resource defined on the page as follows :

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Demos.Views.ListViewPage" Title="ListView">
    <ContentPage.Resources>
        <ResourceDictionary>
            <x:Array x:Key="Countries" Type="{x:Type x:String}">
                <x:String>Afghanistan</x:String>
                <x:String>Albania</x:String>
                <x:String>Algeria</x:String>
                <x:String>Andorra</x:String>
                <x:String>Angola</x:String>
                <x:String>Antigua and Barbuda</x:String>
                <x:String>Argentina</x:String>
                <x:String>Armenia</x:String>
                <x:String>Aruba</x:String>
            </x:Array >
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <ListView ItemsSource="{StaticResource Countries}" />
    </ContentPage.Content>
</ContentPage>

In Code

var countries = new string[] { "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina" };
var listView = new ListView
{
    ItemsSource = countries
};

We have set the countries array as the source for the ListView items.

results matching ""

    No results matching ""