DataGrid MakeDataGrid() { var dataGridFactory = new DataGridFactory(); var dg = dataGridFactory.Make_ColumnHeaderAware_DataGrid(MyIndicators); //Do not use "dg.ItemsSource = MyList", because changing MyList will not be updated in the UI //Use binding instead: BindingOperations.SetBinding(dg, DataGrid.ItemsSourceProperty, new Binding { Source = MyList }); dg.SetValue(Grid.RowProperty, 1); return(dg); }
DataGrid MakeDataGrid() { var dataGridFactory = new DataGridFactory(); var dg = dataGridFactory.Make_ColumnHeaderAware_DataGrid(MyIndicators); //Do not use "dg.ItemsSource = MyList", because changing MyList will not be updated in the UI //Use binding instead: dg.SetBinding(DataGrid.ItemsSourceProperty, new Binding { Source = MyList }); dg.HorizontalAlignment = HorizontalAlignment.Center; dg.VerticalAlignment = VerticalAlignment.Center; dg.SetValue(Grid.RowProperty, 1); return(dg); }