Search code examples
c#uwptimepickeruwp-xaml

How to set TimePicker Header Foreground in UWP?


I can set a Header for my TimePicker, but I can't seem to set the Foreground for that Header. The Foreground property in TimePicker class only changes the text color of the time-selection-box-things.

Looking at the TimePicker class, I would expect the resource TimePickerHeaderForeground to do the job, but I'm honestly not sure how to set that value. Is that a ControlTemplate? How does that work?


Solution

  • I would expect the resource 'TimePickerHeaderForeground' to do the job, but I'm honestly not sure how to set that value.

    TimePickerHeaderForeground is the right way to go. As you can see form the Remarks of TimePicker class, TimePickerHeaderForeground is a Resource key. So we can define a new resource with this special key to modify header's foreground.

    For example, we can define a SolidColorBrush with the key "TimePickerHeaderForeground" in Page.Resources like following:

    <Page ...>
        <Page.Resources>
            <SolidColorBrush x:Key="TimePickerHeaderForeground">Red</SolidColorBrush>
        </Page.Resources>
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <TimePicker Header="Test" />
        </Grid>
    </Page>