I have one question regarding standard WPF DataGrid in .NET 4.0.
When I try to set DataGrid grid row height programmaticaly using simple code:
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Height = 120;
}
everything goes fine till I try to resize grid row on the user interface /standard way on the side using mouse like in excel/ – then it appears grid row can’t be resized. It just keep being 120. Its content by the way all goes messed up…
Like Sinead O’Connor would say: tell me baby – where did I go wrong?
You are not meant to set the Height of the row itself as it is resized via the header and such. There is a property,
DataGrid.RowHeight, which allows you to do this properly.If you need to set the height selectively you can create a style and bind the height of the
DataGridCellsPresenterto some property on your items:Or you can get the presenter from the visual tree (i do not recommend this) and assign a height there:
Where
FindChildOfTypeis an extension method which could be defined like this: