How to change the foreground and background of the selected TabItem's header?
In UWP Tab Control, the Foreground and Background of the selected TabItem’s header can be changed by setting the selectionstyle property as “HeaderText” or “CompleteHeader”. The same has been explained below.
<Grid.Resources> <Style TargetType="navigation:SfTabItem" x:Key="TabItemStyle"> <Setter Property="Background" Value="PaleGreen"/> <Setter Property="SelectedForeground" Value="Brown" /> </Style> </Grid.Resources> <navigation:SfTabControl x:Name="tabControl" SelectionStyle="CompleteHeader" ItemContainerStyle="{StaticResource TabItemStyle}" ItemsSource="{Binding tabctrl}" HorizontalAlignment="Center" VerticalAlignment="Center"> <navigation:SfTabControl.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding TitleName}"/> </DataTemplate> </navigation:SfTabControl.HeaderTemplate> <navigation:SfTabControl.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding content}"/> </DataTemplate> </navigation:SfTabControl.ContentTemplate> </navigation:SfTabControl>
public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); tabctrl = new List<Tabcontrol>(); tabctrl.Add(new Tabcontrol { TitleName = "Item1", content = "content1" }); tabctrl.Add(new Tabcontrol { TitleName = "Item2", content = "content2" }); tabctrl.Add(new Tabcontrol { TitleName = "Item3", content = "content3" }); tabctrl.Add(new Tabcontrol { TitleName = "Item4", content = "content4" }); tabctrl.Add(new Tabcontrol { TitleName = "Item5", content = "content5" }); DataContext = this; } private List<Tabcontrol> tab; public List<Tabcontrol> tabctrl { get { return tab; } set { tab = value; } } } public class Tabcontrol { public string TitleName { get; set; } public string content { get; set; } }
Conclusion
I hope you enjoyed learning about how to change the foreground and background in UWP SfTabControl | Syncfusion.
You can refer to our UWP Tab Control feature tour page to know about its other groundbreaking feature representations documentation 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!