I’ve got a DataGrid completely in code-behind as the whole GUI is dynamically generated.
I have stumbled upon a problem whereby the headers in my dataGrid do not display underscores. I have thus read that wrapping the headers in TextBlocks will solve this problem.
However, my DataGrid’s source is a DataTable, and I am not sure how to go about wrapping the headers of the columns in a TextBlock since everything is auto-generated.
This is my code:
DataGrid dgResults = new DataGrid();
dgResults.IsReadOnly = true;
dgResults.AutoGenerateColumns = true;
dgResults.CanUserAddRows = false;
dgResults.CanUserDeleteRows = false;
dgResults.CanUserReorderColumns = false;
dgResults.CanUserResizeColumns = false;
dgResults.CanUserResizeRows = false;
dgResults.CanUserSortColumns = false;
dgResults.ItemsSource = dtResults.AsDataView();
If anyone has a similar problem, I’ve solved it myself. This can be handled in the DataGrid’s OnColumnGenerating event.