I need to fill WPF DataGrid from DataTable programmatically. List of columns is not know in design time.
Columns should be generated manually (AutoGeneratingColumn event?) based on simple template having single Label. Label.Content is column name. Now binding allowed - template can be created in XAML but everything else need to be in C#
A little bit complex approach is for rows. Data cell template should have single Label or TextBox but cell template should be set in runtime. For instance, string should be represented in cell is longer that 5 chars, then Label-based template should be used. Otherwise, TextBox template should be used. Again, templates only can be created in XAML. Filling data need to be done in C#
Here's some code to start with in order to generate data:
DataTable myTable = new DataTable(tableName);
myTable.Columns.Add(new DataColumn("id", typeof(int)));
myTable.Columns.Add(new DataColumn("name", typeof(string)));
myTable.Rows.Add(new object[] {1, "label"});
myTable.Rows.Add(new object[] {2, "text box"});