Alex Rivera | Logout

WPF DataGrid with variable row heights

Asked 2011-07-20T14:56:42.453
10

I am programmatically creating a DataGrid and need the row heights to be variable so that rows with multiple lines of text have a great height to accomodate the additional lines.

I tried setting the RowHeight property in code, but this requires a fixed value. If I leave RowHeight unset it just uses an arbitrary value that does not expand if the text doesn't fit.

I would also like to have my DataGrid contents to be scaleable, so if the DataGrid is resized the actual cell resize as well, including the font inside the cells. I could use a Viewbox for this, but I've had issues with the Viewbox as it will not grow to fit the text, it shirks/expands the text to fit in it.

Perhaps I need to walk through all of the rows and columns on a resize and set the height property manually.

Edit
Report

1 Answer

12

Try this:

In your Window's constructor, do:

dataGrid.RowHeight = double.NaN;
answered 2011-07-20T15:01:27.073

Your Answer