Created
March 4, 2019 14:20
-
-
Save jfversluis/223f7da154128b06b3997b8c329d6fd3 to your computer and use it in GitHub Desktop.
Set the UnselectedTabColor and SelectedTabColor in the UWP renderer
This file contains 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
void UpdateSelectedTabColors() | |
{ | |
// Retrieve all tab header textblocks | |
var allTabHeaderTextBlocks = Control.GetDescendantsByName<WTextBlock>(TabBarHeaderTextBlockName).ToArray(); | |
// Loop through all pages in the Pivot control | |
foreach (Page page in Control.Items) | |
{ | |
// Fetch just the textblock for the current page | |
var tabBarTextBlock = allTabHeaderTextBlocks[Control.Items.IndexOf(page)]; | |
// Apply selected or unselected style to the current textblock | |
if (page == Element.CurrentPage) | |
{ | |
if (_defaultSelectedColor == null) | |
_defaultSelectedColor = tabBarTextBlock.Foreground; | |
if (Element.IsSet(TabbedPage.SelectedTabColorProperty) && Element.SelectedTabColor != Color.Default) | |
tabBarTextBlock.Foreground = Element.SelectedTabColor.ToBrush(); | |
else | |
tabBarTextBlock.Foreground = _defaultSelectedColor; | |
} | |
else | |
{ | |
if (_defaultUnselectedColor == null) | |
_defaultUnselectedColor = tabBarTextBlock.Foreground; | |
if (Element.IsSet(TabbedPage.SelectedTabColorProperty) && Element.UnselectedTabColor != Color.Default) | |
tabBarTextBlock.Foreground = Element.UnselectedTabColor.ToBrush(); | |
else | |
tabBarTextBlock.Foreground = _defaultUnselectedColor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment