Hi,
I would like to make the contents of header row vertical. This will save me space, since the header takes up a lot of space. Every other row would be as before, that is horizontal text. How would I achieve this?
Hello,
I have been looking into your question and you can create a style for the LabelPresenter where to set the a vertical TextBlock in the ContentPresenter. Also you need to set the ‘Width’ property to “Auto”. I am attaching a sample application(DataGridVerticalHeaders.zip) that shows my approach.
Let me know, if you need any further assistance on this matter.
many thanks. It worked.
I am just checking if you require any further assistance on the matter.
Thank you for your feedback. I notices that the text in some of the header is cut, if it is too long. My suggestion is to set the ‘Height’ property of the TextBlock to value which can meet your scenario. In my sample application, it could be “150”. Also some letters which take smaller space makes two letters appear on one line. If you want to avoid this functionality you can add an empty symbol after each of them by handling the ‘Loaded’ event of the TextBlock like e.g. :
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
{
StringBuilder MyStringBuilder = new StringBuilder((sender as TextBlock).Text);
MyStringBuilder.Replace("i", "i ");
MyStringBuilder.Replace("l", "l ");
MyStringBuilder.Replace("e", "e ");
MyStringBuilder.Replace("r", "r ");
(sender as TextBlock).Text = MyStringBuilder.ToString();
}
Please note that there is no built-in feather for the functionality that you are looking for and my suggestion is a custom approach.
Let me know, if you have any other questions on this matter.
I noticed that in your example, the last column Mileage, the text gets cut off. Do you also see the same thing?