-
Notifications
You must be signed in to change notification settings - Fork 20
Added new kb article datagrid-column-header-word-wrap #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
github-actions
wants to merge
1
commit into
master
Choose a base branch
from
new-kb-datagrid-column-header-word-wrap-b3d6d7ed40f04f19a9286725653f27be
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| --- | ||
| title: Enabling Word Wrapping for Column Headers in DataGrid for UI for .NET MAUI | ||
| description: Learn how to enable word wrapping for column headers in DataGrid for UI for .NET MAUI by using a header template. | ||
| type: how-to | ||
| page_title: How to Enable Word Wrapping in DataGrid Column Headers for UI for .NET MAUI | ||
| meta_title: How to Enable Word Wrapping in DataGrid Column Headers for UI for .NET MAUI | ||
| slug: datagrid-column-header-word-wrap | ||
| tags: datagrid, ui for .net maui, column header, wordwrap, template | ||
| res_type: kb | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| | Version | Product | Author | | ||
| | --- | --- | ---- | | ||
| | 11.1.0 | Telerik UI for .NET MAUI DataGrid | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | | ||
|
|
||
| ## Description | ||
|
|
||
| I want to enable word wrapping for the column header text in the [DataGrid for UI for .NET MAUI](https://www.telerik.com/maui-ui/documentation/controls/datagrid/overview). This feature allows text in the header to wrap to the next line when it exceeds the width of its container. | ||
|
|
||
| This knowledge base article also answers the following questions: | ||
| - How do I apply word wrapping in DataGrid column headers? | ||
| - Can I use a template for DataGrid column headers in UI for .NET MAUI? | ||
| - How to format text in a DataGrid column header? | ||
|
|
||
| ## Solution | ||
|
|
||
| To enable word wrapping for column headers, use a template for the `HeaderContentTemplate` property of a `DataGridTextColumn`. The template allows customization of the header's appearance, including enabling word wrapping for text. | ||
|
|
||
| ### Example in XAML | ||
|
|
||
| ```xml | ||
| <telerik:DataGridTextColumn.HeaderStyle> | ||
| <Style TargetType="telerik:DataGridColumnHeaderAppearance"> | ||
| <Setter Property="BackgroundColor" Value="#00796B" /> | ||
| <Setter Property="SortIndicatorColor" Value="#FFFFFF" /> | ||
| <Setter Property="FilterIndicatorTextColor" Value="#99FFFFFF" /> | ||
| <Setter Property="FilterIndicatorActiveTextColor" Value="#80CBC4" /> | ||
| </Style> | ||
| </telerik:DataGridTextColumn.HeaderStyle> | ||
| <telerik:DataGridTextColumn.HeaderContentTemplate> | ||
| <DataTemplate> | ||
| <Label Text="Capital fsfsgsd fsdfsdfsdfsd" | ||
| FontSize="20" | ||
| FontAttributes="Bold" | ||
| LineBreakMode="WordWrap" | ||
| HorizontalTextAlignment="Center" | ||
| VerticalTextAlignment="Center" /> | ||
| </DataTemplate> | ||
| </telerik:DataGridTextColumn.HeaderContentTemplate> | ||
| ``` | ||
|
|
||
| ### Example in C# | ||
|
|
||
| ```csharp | ||
| var headerTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label | ||
| { | ||
| Text = "Hello gregreg g re gre g reg re g", | ||
| FontSize = 20, | ||
| FontAttributes = FontAttributes.Bold, | ||
| LineBreakMode = LineBreakMode.WordWrap, | ||
| HorizontalTextAlignment = TextAlignment.Center, | ||
| HorizontalOptions = LayoutOptions.Fill, | ||
| VerticalTextAlignment = TextAlignment.Center, | ||
| Margin = new Thickness(4, 0) | ||
| }; | ||
|
|
||
| return label; | ||
| }); | ||
|
|
||
| var nameColumn = new DataGridTextColumn | ||
| { | ||
| PropertyName = nameof(Models.Person.Name), | ||
| HeaderText = "Name", | ||
| HeaderContentTemplate = headerTemplate | ||
| }; | ||
| dataGrid.Columns.Add(nameColumn); | ||
| ``` | ||
|
|
||
| ### Notes | ||
|
|
||
| When using a template, it overrides the properties set in the `HeaderStyle` for the text. Define properties such as font size, font attributes, and text color directly in the label inside the template. | ||
|
|
||
| ## See Also | ||
|
|
||
| - [DataGrid Column Header Styling](https://www.telerik.com/maui-ui/documentation/controls/datagrid/theming-and-styles/columns-styling#header-styling) | ||
| - [Customizing DataGrid Columns](https://www.telerik.com/maui-ui/documentation/controls/datagrid/columns/overview) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this line in the Solution section.