Results 1 to 2 of 2

Thread: How to set width(height) of vertically set column headers in datagrid?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    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?

  2. #2

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    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
  •  



Click Here to Expand Forum to Full Width