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 responses to “Video : ListBox Data Binding in Windows Phone”

  1. […] Video : ListBox Data Binding in Windows Phone (Dhananjay Kumar) […]

  2. […] If you are not aware of Data Binding in ListBox then watch a quick Video here […]

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 )

Facebook photo

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

Connecting to %s

Create a website or blog at WordPress.com