Set DataGrid AutoGenerateColumns="False"
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); BindDataGrid(GetTwoDimensinalArray()); } string[,] GetTwoDimensinalArray() { //Generating two dimensional array string[,] returnValue = new string[5, 5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { returnValue[i,j] = "cell [" + i.ToString() + "," + j.ToString() + "]"; } } return returnValue; } void BindDataGrid(string[,] _array) { ObservableCollection<ObservableCollection<string>> dataSource = new ObservableCollection<ObservableCollection<string>>(); //converting two dimensional array into ObservableCollection for (int i = 0; i < 5; i++) { ObservableCollection<string> row = new ObservableCollection<string>(); for (int j = 0; j < 5; j++) { row.Add(_array[i, j]); } dataSource.Add(row); } for (int i = 0; i < 5; i++) { //Creating Datagrid columns and binding them to their apropriate columns DataGridTextColumn dataColumn = new DataGridTextColumn(); dataColumn.Header = "Column "+i.ToString(); dataColumn.Binding = new Binding("[" + i.ToString() + "]"); dataGridSample.Columns.Add(dataColumn); } //Binding DataGrid with collection dataGridSample.ItemsSource = dataSource; } }
How can I add the "PresentationFrameword.dll" to the Silverlight application to use the "Binding" method ?
ReplyDeleteHere you have your answer
Deletehttp://social.msdn.microsoft.com/Forums/silverlight/en-US/d884e231-9ee9-4371-89f4-627569515545/agclr-and-presentationframework-clashing-over-building-or-designer-working?forum=silverlightdevtools
It works...... Thanks :)
ReplyDelete