Saturday, December 4, 2010

How to add items to Windows Phone 7 ListPicker

I figured  out how to add list items from code behind. For some one who might have a similar problem, my solution is given below.
I created an observable collection

Code behind

int startyear 2000;
int endyear 2010;
ObservableCollection<string> yearlist = new ObservableCollection<string>();
for (int i = endyear; i >= startyear; i--)
{
yearlist.Add(i.ToString());
}
YearListPicker.ItemsSource = yearlist;



XAML



<toolkit:ListPicker  Margin="4,4,4,4" 
x:Name="YearListPicker" Header="Year" >
</toolkit:ListPicker>



Interesting article on ListPicker



http://blogs.msdn.com/b/delay/archive/2010/11/03/listpicker-i-hardly-even-know-er-a-detailed-overview-of-the-windows-phone-toolkit-s-listpicker-control.aspx

No comments:

Post a Comment