- Create new page
- Create new class for listing properties
public class ListViewTemplate
{
public string Name { get; set; }
public string Description { get; set; }
public int OrderNumber { get; set; }
}
- Add listview in page
<?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="App1.MainMaster"
Title="My Application">
<ListView x:Name="MainList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}"></Label>
<Label Text="{Binding Description}"></Label>
<Label Text="{Binding OrderNumber}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
- Write a code to bind listview
public partial class MainMaster : ContentPage
{
public MainMaster()
{
InitializeComponent();
MainList.ItemsSource = new List<ListViewTemplate>
{
new ListViewTemplate { Name="One", Description="One", OrderNumber=1 },
new ListViewTemplate { Name="Two", Description="Two", OrderNumber=2 },
new ListViewTemplate { Name="Three", Description="Three", OrderNumber=3 }, new ListViewTemplate { Name="Four", Description="Four", OrderNumber=4 },
new ListViewTemplate { Name="Five", Description="Five", OrderNumber=5 },
};
}
}
- Set page in to run the application
public class App : Application
{
public App()
{
MainPage = new MainMaster();
}
}
- Run the application
This is really nice post for beginner. Thanks for this post. Waiting new post on xamarin.
ReplyDelete