DataGrid-Fit to Contents

Mar 8, 2010 at 11:49 AM

I have a DataGrid inside a WPF application and I want it to fit to Contents. I set ItemSource  to a DataTable via code.

How can I change DataGrid Wight/Height according to my contents programmatically???

In DataGridView I do the following, which doesn't work here:

for (int i = 0; i <= dataGridView.Rows.Count - 1; i++)
     totHeight = dataGridView.Rows[i].Height + totHeight;