Wednesday, December 26, 2012

Simple binding in Silverlight datagrid

Here I created a class name "Friends" and initialize its objects in declarative manner with generic class to bind the Silverlight datacontrol datagrid. public class Friends
        public string FirstName{get;set;}
        public string City {get;set;}

in MainPage.xaml file drag and drop the "DataGrid" control in canvas area and now code looks like below

In MainPage.xaml.cs copy the code

  List list = new List()
                new Friends{FirstName="Murugesan",City="NewYork"},
                new Friends{FirstName="NagaJothy",City="Kovil Patti"},
                new Friends{FirstName="TPK Senthilan",City="Chennai"}
            dataGrid1.ItemsSource = list;