TimePicker styles and templates

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

This topic describes the styles and templates for the TimePicker control. You can modify these resources and the default ControlTemplate to give the control a unique appearance.

Visual states

The TimePicker default style doesn't define any visual states.

Theme resources

These resources are used in the control's default style.

Dark theme brushes

To change the colors of the control in the dark theme, override these brushes in App.xaml.

<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush"  Color="#FF000000" />

Light theme brushes

To change the colors of the control in the light theme, override these brushes in App.xaml.

<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush" Color="#FF000000" />

Other resources

<x:Double x:Key="TimePickerSelectorThemeMinWidth">80</x:Double>
<Thickness x:Key="TimePickerHeaderThemeMargin">0,0,0,6</Thickness>
<Thickness x:Key="TimePickerFirstHostThemeMargin">0,0,20,0</Thickness>
<Thickness x:Key="TimePickerThirdHostThemeMargin">20,0,0,0</Thickness>
<FontWeight x:Key="TimePickerHeaderThemeFontWeight">SemiLight</FontWeight>

Shared resources

The control template uses these resources that are shared with other control templates. Changing these values will affect other controls that use these resources.

<FontFamily x:Key="ContentControlThemeFontFamily">Segoe UI</FontFamily>
<x:Double x:Key="ControlContentThemeFontSize">14.667</x:Double>

For more info on theme resources, including the values that are used for the HighContrast theme, see XAML theme resources reference.

Default style

<!-- Default style for Windows.UI.Xaml.Controls.TimePicker -->
<Style TargetType="TimePicker">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
    <Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}"/>
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TimePicker">
                 <Border x:Name="LayoutRoot"
                              Background="{TemplateBinding Background}"
                              BorderBrush="{TemplateBinding BorderBrush}"
                              BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid Margin="{TemplateBinding Padding}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ContentPresenter x:Name="HeaderContentPresenter"
                                          Foreground="{ThemeResource TimePickerHeaderForegroundThemeBrush}"
                                          Margin="{ThemeResource TimePickerHeaderThemeMargin}"
                                          FlowDirection="{TemplateBinding FlowDirection}"
                                          Content="{TemplateBinding Header}"
                                          ContentTemplate="{TemplateBinding HeaderTemplate}"
                                          FontWeight="{ThemeResource TimePickerHeaderThemeFontWeight}" />
                        <StackPanel Grid.Row="1" Orientation="Horizontal">
                             <Border x:Name="FirstPickerHost" Margin="{ThemeResource TimePickerFirstHostThemeMargin}">
                                 <ComboBox x:Name="HourPicker"
                                                    MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
                                                    FontWeight="{TemplateBinding FontWeight}"
                                                    FontSize="{TemplateBinding FontSize}"
                                                    FontFamily="{TemplateBinding FontFamily}"
                                                    Foreground="{TemplateBinding Foreground}"/>
                             </Border>
                             <Border x:Name="SecondPickerHost">
                                 <ComboBox x:Name="MinutePicker" 
                                                    MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
                                                    FontWeight="{TemplateBinding FontWeight}"
                                                    FontSize="{TemplateBinding FontSize}"
                                                    FontFamily="{TemplateBinding FontFamily}"
                                                    Foreground="{TemplateBinding Foreground}"/>
                             </Border>
                             <Border x:Name="ThirdPickerHost" Margin="{ThemeResource TimePickerThirdHostThemeMargin}">
                                 <ComboBox x:Name="PeriodPicker" 
                                                    MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
                                                    FontWeight="{TemplateBinding FontWeight}"
                                                    FontSize="{TemplateBinding FontSize}"
                                                    FontFamily="{TemplateBinding FontFamily}"
                                                    Foreground="{TemplateBinding Foreground}"/>
                             </Border>
                         </StackPanel>
                     </Grid>
                 </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>