I'm trying to override the Pivot header foreground theme brushes, but no matter what I do the UWP app just ignores it.
Just to be clear, this question is about the UWP Pivot control, not the Win (Phone) 8.1 one. I've used the theme brush override method in a 8.1 app and it worked perfectly. But I can't seem to be able to do the same for a UWP Pivot.
I looked for the respective brushes in generic.xaml (and in the Properties pane under Brushes -> System Brush Resources), which are PivotHeaderForegroundSelectedBrush and PivotHeaderForegroundUnselectedBrush in a UWP app, and added them to my resource dictionary in app.xaml, but unlike the other system brushes, the Pivot ones aren't overridden for some reason.
<SolidColorBrush x:Key="SystemControlForegroundAccentBrush" Color="Gray"/>
<SolidColorBrush x:Key="SystemControlBackgroundAccentBrush" Color="Gray"/>
<SolidColorBrush x:Key="SystemColorControlAccentBrush" Color="Gray"/>
<SolidColorBrush x:Key="PivotHeaderForegroundSelectedBrush" Color="Green" />
<SolidColorBrush x:Key="PivotHeaderForegroundUnselectedBrush" Color="Red"/>
I know other ways to change the header foreground color, but that might involve converters or extra code behind, which I'd rather not use to be honest if i can do it in a clean way. I tried editing the default Pivot style, but I don't see anywhere where I can add/edit a Foreground property for the header items in the default Pivot style.
Thanks in advance! :)
Interestingly, the
Foreground
property of thePivotItemStyle
controls the foreground color of the content within thePivotItem
, not the header of it. And there's no way to modify the color of the header within the style.You might be able to find the corresponding color resources and modify them to achieve what you want, but here's a more flexible and pure xaml way -
The
Pivot
control actually has aHeaderTemplate
which allows you to fully customise yourPivotItem
headers. See the following code sample, all the headers should have the Teal color.Update
So here is a better way.
I used the new Live Visual Tree tool in Visual Studio to help locate the actual header element. It's a control called
PivotHeaderItem
. So turns out, all the styling is defined within this control.I then had to go to msdn and grabbed the full style of this control (Blend didn't work).
As you can see within the style, the control has a default
Foreground
of{ThemeResource SystemControlForegroundBaseMediumBrush}
and within the visual states, thisForeground
gets changed to{ThemeResource SystemControlHighlightAltBaseHighBrush}
when the state goes toSelected
. I've changed them toRed
andGreen
to make them more obvious.With this, you should now be able to fully customise your pivot headers! :)