Articles in this section
Category / Section

How to wrap the text and increase the height of the stacked header row based on that in WPF DataGrid ?

2 mins read

Wrap the text in StackedHeader Row

You can wrap the text in StackedHeader cell by writing the style for GridStackedHeaderCellControl in WPF DataGrid (SfDataGrid) and setting TextWrapping as Wrap to the TextBlock.

XAML

<Style TargetType="Syncfusion:GridStackedHeaderCellControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Syncfusion:GridStackedHeaderCellControl">
                <Border Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid Margin="{TemplateBinding Padding}">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" >
                            <ContentPresenter.Content>
                                <TextBlock Text="{Binding HeaderText}"  TextWrapping="Wrap"/>
                            </ContentPresenter.Content>
                        </ContentPresenter>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

 

Height based on StackedHeader cell content

You can set the height for StackedHeader row by handling QueryRowHeight event in WPF DataGrid (SfDataGrid). In the below code StackedHeader row height is set based on content by calling GridColumnsizer.GetAutoRowHeight method.

C#

datagrid.QueryRowHeight += datagrid_QueryRowHeight;
 
void datagrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
    if (e.RowIndex < this.datagrid.StackedHeaderRows.Count)
    {
       if (this.datagrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out Height))
       {
          if (Height > this.datagrid.RowHeight)
          {
             e.Height = Height;
             e.Handled = true;
          }
       }
    }
}

 

SFDataGrid Demo

Sample:

WPF

WinRT

UWP


Conclusion

I hope you enjoyed learning about how to wrap the text and increase the height of the StackedHeader row based on that in WPF DataGrid.

You can refer to our WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied