Video : ListBox Data Binding in Windows Phone


using System.Collections.Generic;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.DataContext = GetProducts();
}

private List<Product> GetProducts()
{
List<Product> lstProduct = new List<Product>
{
new Product { ProductName ="Pen" , ProductCat ="Education" , ProductPrice = 100 },
new Product { ProductName ="Pencil" , ProductCat ="Education" , ProductPrice = 200 },
new Product { ProductName ="Bat" , ProductCat ="Sports" , ProductPrice = 400 },
new Product { ProductName ="Ball" , ProductCat ="Sprots" , ProductPrice = 90 },
new Product { ProductName ="Eraser" , ProductCat ="Education" , ProductPrice = 10 },
new Product { ProductName ="Shoes" , ProductCat ="Sports" , ProductPrice = 790 },
new Product { ProductName ="NoteBook" , ProductCat ="Education" , ProductPrice = 345 },
new Product { ProductName ="Cycle" , ProductCat ="Sports" , ProductPrice = 5000 },
new Product { ProductName ="Gel Pen" , ProductCat ="Education" , ProductPrice = 130 },
new Product { ProductName ="Football" , ProductCat ="Sports" , ProductPrice = 440 },
new Product { ProductName ="Hockey Stick" , ProductCat ="Sports" , ProductPrice = 320 },
new Product { ProductName ="Drwaing  Book" , ProductCat ="Education" , ProductPrice = 480 },
new Product { ProductName ="Novel" , ProductCat ="Education" , ProductPrice = 180 },
new Product { ProductName ="Tenis Bat" , ProductCat ="Sports" , ProductPrice = 340 },
new Product { ProductName ="Tenis Ball" , ProductCat ="Sports" , ProductPrice = 46 }

};
return lstProduct;

}
}

public class Product
{
public string ProductName { get; set; }
public string ProductCat { get; set; }
public int ProductPrice { get; set; }
}
}


<ListBox x:Name="lstProduct" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding ProductName}" Style="{StaticResource PhoneTextTitle2Style}" />
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding ProductCat}" Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Text="{Binding ProductPrice}" Style="{StaticResource PhoneTextAccentStyle }" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

2 thoughts on “Video : ListBox Data Binding in Windows Phone

  1. Pingback: Dew Drop – September 10, 2012 (#1,397) | Alvin Ashcraft's Morning Dew

  2. Pingback: ASP.Net Web API Service in Windows Phone: Part 4 of Many « debug mode……

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s