Using the Microsoft DataGrid with the MVVM pattern in the following way works for me because the DataGrid automatically generates the columns based on a DataTable.
In XAML I include the DataGrid:
<WpfToolkit:DataGrid
ItemsSource="{Binding Path=GridData, Mode=OneWay}" >
</WpfToolkit:DataGrid>
In my view model I expose a DataView:
public DataView GridData
{
get
{
DataSet ds = new DataSet("MyDataSet");
// everything hard-coded for this example
int to = 12;
int ps = 2048;
string sv = "10";
string st = "Open";
string wsid = "ZAMBONI";
DataTable dt = new DataTable("MyDataTable");
DataColumn propertyName = new DataColumn("Property");
DataColumn propertyValue = new DataColumn("Value");
dt.Columns.Add(propertyName);
dt.Columns.Add(propertyValue);
dt.Rows.Add("Connection timeout", to);
dt.Rows.Add("Packet size", ps);
dt.Rows.Add("Server version", sv);
dt.Rows.Add("State", st);
dt.Rows.Add("Worksation id", wsid);
ds.Tables.Add(dt);
return ds.Tables[0].DefaultView;
}
}