Articles in this section
Category / Section

How to show multi-line header text in Xamarin.FormsDataGrid?

1 min read

Xamarin.Forms DataGrid allows you to customize the header text for a GridColumn by using the HeaderText property. However by default the grid displays only single line of text in the header and hence when you load a longer header text, the SfDataGrid clips them and displays an ellipsoid at the end.

 

In case, if longer text need to be displayed in the header, then SfDataGrid allows you to achieve it by using the HeaderTemplate property in the GridColumn. The HeaderTemplate replaces the default header view. Hence you can use it to load a label with LineBreakMode property being set to WordWrap. This will wrap the header text to the next line. You can use the HeaderRowHeight property to customize the header row height as required based on your header text.

 

Refer the following code example which illustrates how to show multiline header in SfDataGrid.

 

<sfGrid:SfDataGrid  x:Name="dataGrid"
                                  ItemsSource="{Binding OrdersInfo}"
                                  HeaderRowHeight="70"> 
  <sfGrid:SfDataGrid.Columns x:TypeArguments="sfgrid:Columns">      
     <sfGrid:GridTextColumn MappingName="PatientName">
       <sfGrid:GridTextColumn.HeaderTemplate>
         <DataTemplate>
            <Label x:Name="PatientName" Text="Demo For Multi line Text in header"
                        TextColor="Black" VerticalOptions="Fill" 
                        YAlign="Center" Align="Center" 
                        LineBreakMode="WordWrap"  />                                        
         </DataTemplate>
       </sfGrid:GridTextColumn.HeaderTemplate>
     </sfGrid:GridTextColumn>
   </sfGrid:SfDataGrid.Columns> </sfGrid:SfDataGrid>

 

The following screenshot shows the final outcome on executing the above code.

 

Multiple haeder in SfDataGrfid

 

 

 

You can download a working sample for this KB from the below link.



Conclusion

I hope you enjoyed learning about how to show multi-line header text in Xamarin.FormsDataGrid


You can refer to our Xamarin.Forms 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 Xamarin.Forms 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