RadDataGrid Column HeaderText wrapping

1 Answer 71 Views
DataGrid
Satya
Top achievements
Rank 1
Satya asked on 17 Aug 2023, 05:35 PM

Hi,

I was trying to wrap the column header text for some of my columns in below DataGrid. for eg: Mininum Degree, Maximum Degree I want them to displayed in 2 lines: 
Minimum  |   Maximum
Degree          Degree

I have tried line breaks but didn't work

 

<telerik:RadDataGrid x:Name="SubfactorsGrid" ItemsSource="{Binding Subfactors}" AutoGenerateColumns="False" UserEditMode="None"
SelectionUnit="Row" RowHeight="30">
<telerik:RadDataGrid.Columns>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="SubfactorKey" HeaderText="Key" SizeMode="Fixed" Width="100"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="Name" HeaderText="Subfactor" SizeMode="Fixed" Width="250"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="MinimumDegree" HeaderText="Minimum Degree" SizeMode="Fixed" Width="150"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="MaximumDegree" HeaderText="Maximum Degree" SizeMode="Fixed" Width="150"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="Granularity" HeaderText="Degree Granularity" SizeMode="Fixed" Width="150"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="PercentWeight" HeaderText="Percent Weight" SizeMode="Fixed" Width="150"/>
<telerik:DataGridTextColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="DisplayOrder" HeaderText="Display Order" SizeMode="Fixed" Width="150"/>
<telerik:DataGridBooleanColumn HeaderStyle="{StaticResource columHeaderStyle}" PropertyName="IsOverrideProgression" HeaderText="Override Progression" SizeMode="Fixed" Width="200">
<telerik:DataGridColumn.CellContentTemplate>
<DataTemplate>
<telerik:RadCheckBox IsChecked="{Binding IsOverrideProgression}" IsEnabled="False"/>
</DataTemplate>
</telerik:DataGridColumn.CellContentTemplate>
</telerik:DataGridBooleanColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 18 Aug 2023, 05:45 AM

Hi Satya,

Try using the HeaderContentTemplate. Then add a Label inside the template and set its LineBreakMode property to WordWrap:

 <DataTemplate x:Key="CapitalColumnHeaderTemplate">
            <VerticalStackLayout WidthRequest="70" BackgroundColor="Red">
               
                <Label Text="Minimum degree" 
                       LineBreakMode="WordWrap"
                       HorizontalOptions="Center"
                       VerticalOptions="Center"
                       Margin="4, 0, 0, 0" />
            </VerticalStackLayout>
        </DataTemplate>

The header template allows you to fully customize the column header.

Regards,
Didi
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Tags
DataGrid
Asked by
Satya
Top achievements
Rank 1
Answers by
Didi
Telerik team
Share this question
or