|
| 1 | +--- |
| 2 | +title: Applying Gradient to TabView Header for .NET MAUI |
| 3 | +description: Learn how to apply a gradient background to the Header of the TabView component in .NET MAUI. |
| 4 | +type: how-to |
| 5 | +page_title: Setting Gradient Background for TabView Header in .NET MAUI |
| 6 | +slug: gradient-header-tabview-dotnet-maui |
| 7 | +tags: tabview,.net maui, header, gradient, tabviewheaderitem |
| 8 | +res_type: kb |
| 9 | +--- |
| 10 | + |
| 11 | +## Environment |
| 12 | + |
| 13 | +| Version | Product | Author | |
| 14 | +| --- | --- | ---- | |
| 15 | +| 11.0.0 | Telerik UI for .NET MAUI TabView | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +I want to apply a gradient background to the headers of the TabView component in .NET MAUI. The headers' background needs to be styled using a `LinearGradientBrush` while maintaining custom styling for other properties like `FontAttributes` and `TextColor`. |
| 20 | + |
| 21 | +This knowledge base article also answers the following questions: |
| 22 | +- How to set a gradient background for TabView headers in .NET MAUI? |
| 23 | +- How to customize TabView `HeaderItemStyle` in .NET MAUI? |
| 24 | +- How to use `LinearGradientBrush` in TabView `HeaderItemStyle`? |
| 25 | + |
| 26 | +## Solution |
| 27 | + |
| 28 | +To apply a gradient background to the headers in the TabView component, define a custom `HeaderItemStyle` targeting the `TabViewHeaderItem`. Use the `LinearGradientBrush` to specify the gradient background. Below is an example implementation: |
| 29 | + |
| 30 | +```xml |
| 31 | +<telerik:RadTabView x:Name="tabView"> |
| 32 | + <telerik:RadTabView.HeaderItemStyle> |
| 33 | + <Style TargetType="telerik:TabViewHeaderItem"> |
| 34 | + <!-- Customize font style --> |
| 35 | + <Setter Property="FontAttributes" Value="Italic"/> |
| 36 | + <!-- Customize text color --> |
| 37 | + <Setter Property="TextColor" Value="#99000000" /> |
| 38 | + <!-- Apply gradient background --> |
| 39 | + <Setter Property="Background"> |
| 40 | + <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> |
| 41 | + <GradientStop Color="Blue" Offset="0.0"/> |
| 42 | + <GradientStop Color="Blue" Offset="0.4"/> |
| 43 | + <GradientStop Color="Red" Offset="0.6"/> |
| 44 | + <GradientStop Color="Red" Offset="1.0"/> |
| 45 | + </LinearGradientBrush> |
| 46 | + </Setter> |
| 47 | + </Style> |
| 48 | + </telerik:RadTabView.HeaderItemStyle> |
| 49 | + <!-- Define TabView items --> |
| 50 | + <telerik:TabViewItem HeaderText="Home"> |
| 51 | + <Label Margin="10" Text="This is the content of the Home tab" /> |
| 52 | + </telerik:TabViewItem> |
| 53 | + <telerik:TabViewItem HeaderText="Folder"> |
| 54 | + <Label Margin="10" Text="This is the content of the Folder tab" /> |
| 55 | + </telerik:TabViewItem> |
| 56 | + <telerik:TabViewItem HeaderText="View"> |
| 57 | + <Label Margin="10" Text="This is the content of the View tab" /> |
| 58 | + </telerik:TabViewItem> |
| 59 | +</telerik:RadTabView> |
| 60 | +``` |
| 61 | + |
| 62 | +## See Also |
| 63 | + |
| 64 | +- [TabView Documentation](https://docs.telerik.com/devtools/maui/controls/tabview/overview) |
0 commit comments