-
Jul 24th, 2019, 07:28 AM
#1
Thread Starter
Addicted Member
How to set width(height) of vertically set column headers in datagrid?
I am using this code for my DataGrid
Code:
<DataGrid
Grid.Row="1"
Name="myDataGrid"
SelectedItem="{Binding chosenReport, Mode=TwoWay}"
ItemsSource="{Binding Reports, Mode=TwoWay}"
IsReadOnly="True"
FontSize="14"
AutoGenerateColumns="False">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="270" />
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Field 1. Bla blabla blabla blabla blabla blablablabla blablablabla blabla" Binding="{Binding Path=Field1}" />
<DataGridTextColumn Header="Field 2. Bla blabla blabla blabla blabla blablablabla blablablabla blabla Bla blabla blabla blabla blabla blablablabla blablablabla blabla" Binding="{Binding Path=Field2}" />
<DataGridTextColumn Header="Field 3. Bla blabla blabla blabla blabla blablablabla blablablabla blabla tralalaalalalaal" Binding="{Binding Path=Field3}" />
<DataGrid.Columns/>
<DataGrid/>
Yes it works and it shows all DataGrid fields vertically. However, since the text in the column headers are quite long, I don't see the data in the datagrid because it is covered with text from the headers.
How can I tell the DataGrid to make some sort of word wrap to put the text in each column header in several "vertical rows"?
Or maybe there is height(width) of the column header?
-
Jul 25th, 2019, 12:19 AM
#2
Thread Starter
Addicted Member
Re: How to set width(height) of vertically set column headers in datagrid?
I got an answer(https://stackoverflow.com/questions/...rs-in-datagrid) on SO:
Code:
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid MaxWidth="160">
<Grid.LayoutTransform>
<RotateTransform Angle="270" />
</Grid.LayoutTransform>
<TextBlock
TextWrapping="WrapWithOverflow"
Text="{Binding}"
/>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|