|
| 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 effect to the entire header of the [TabView]({%slug tabview-overview%}) component in .NET MAUI, not just individual header items. Additionally, I need transparency for the background and border properties of the header items. |
| 20 | + |
| 21 | +This knowledge base article also answers the following questions: |
| 22 | +- How to style the TabView header with a gradient in .NET MAUI? |
| 23 | +- How to use `HeaderTemplate` for TabView in .NET MAUI? |
| 24 | +- How to apply transparency to TabView header items in .NET MAUI? |
| 25 | + |
| 26 | +## Solution |
| 27 | + |
| 28 | +To achieve a gradient effect for the entire TabView header and apply transparency to the header items, follow these steps: |
| 29 | + |
| 30 | +1. Define a `LinearGradientBrush` resource for the gradient effect. |
| 31 | +2. Create a `ControlTemplate` for the header and use the gradient brush in its background property. |
| 32 | +3. Set transparency for the header item background and border properties using the `HeaderItemStyle`. |
| 33 | + |
| 34 | +```xaml |
| 35 | +<ContentPage.Resources> |
| 36 | + <ResourceDictionary> |
| 37 | + <!-- Gradient Brush for Header Background --> |
| 38 | + <LinearGradientBrush x:Key="brush" StartPoint="0,0" EndPoint="1,1"> |
| 39 | + <GradientStop Color="Blue" Offset="0.0"/> |
| 40 | + <GradientStop Color="Blue" Offset="0.4"/> |
| 41 | + <GradientStop Color="Red" Offset="0.6"/> |
| 42 | + <GradientStop Color="Red" Offset="1.0"/> |
| 43 | + </LinearGradientBrush> |
| 44 | + |
| 45 | + <!-- Header Control Template --> |
| 46 | + <ControlTemplate x:Key="TabViewHeaderControlTemplate"> |
| 47 | + <telerikMauiControls:RadBorder Background="{StaticResource brush}" |
| 48 | + BorderColor="{TemplateBinding BorderColor}" |
| 49 | + BorderThickness="{TemplateBinding BorderThickness}" |
| 50 | + CornerRadius="{TemplateBinding CornerRadius}" |
| 51 | + Padding="{TemplateBinding ContentPadding}" |
| 52 | + AutomationId="RadTabViewHeader"> |
| 53 | + <ContentPresenter /> |
| 54 | + </telerikMauiControls:RadBorder> |
| 55 | + </ControlTemplate> |
| 56 | + </ResourceDictionary> |
| 57 | +</ContentPage.Resources> |
| 58 | + |
| 59 | +<telerik:RadTabView x:Name="tabView" HeaderTemplate="{StaticResource TabViewHeaderControlTemplate}"> |
| 60 | + <!-- Style for Header Items --> |
| 61 | + <telerik:RadTabView.HeaderItemStyle> |
| 62 | + <Style TargetType="telerik:TabViewHeaderItem"> |
| 63 | + <Setter Property="FontAttributes" Value="Italic"/> |
| 64 | + <Setter Property="TextColor" Value="#99000000" /> |
| 65 | + <Setter Property="Background" Value="Transparent"/> |
| 66 | + <Setter Property="BackgroundColor" Value="Transparent"/> |
| 67 | + <Setter Property="BorderColor" Value="Transparent"/> |
| 68 | + </Style> |
| 69 | + </telerik:RadTabView.HeaderItemStyle> |
| 70 | + |
| 71 | + <!-- Tab Items --> |
| 72 | + <telerik:TabViewItem HeaderText="Home"> |
| 73 | + <Label Margin="10" Text="This is the content of the Home tab" /> |
| 74 | + </telerik:TabViewItem> |
| 75 | + <telerik:TabViewItem HeaderText="Folder"> |
| 76 | + <Label Margin="10" Text="This is the content of the Folder tab" /> |
| 77 | + </telerik:TabViewItem> |
| 78 | + <telerik:TabViewItem HeaderText="View"> |
| 79 | + <Label Margin="10" Text="This is the content of the View tab" /> |
| 80 | + </telerik:TabViewItem> |
| 81 | +</telerik:RadTabView> |
| 82 | +``` |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +- [TabView Documentation]({%slug tabview-overview%}) |
| 87 | +- [Applying Gradient to TabView Header Item for .NET MAUI]({%slug gradient-header-item-tabview-dotnet-maui%}) |
0 commit comments