DatePicker 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 DatePicker control. You can modify these resources and the default ControlTemplate to give the control a unique appearance.

Visual states

The DatePicker 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="DatePickerHeaderForegroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="DatePickerForegroundThemeBrush"  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="DatePickerHeaderForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="DatePickerForegroundThemeBrush" Color="#FF000000" />

Other resources

<x:Double x:Key="DatePickerSelectorThemeMinWidth">80</x:Double>
<x:Double x:Key="DatePickerSpacingThemeWidth">20</x:Double>
<x:Double x:Key="DatePickerSpacingThemeHeight">20</x:Double>
<Thickness x:Key="DatePickerHeaderThemeMargin">0,0,0,6</Thickness>
<FontWeight x:Key="DatePickerHeaderThemeFontWeight">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.DatePicker -->
<Style TargetType="DatePicker">
    <Setter Property="Orientation" Value="Horizontal"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
    <Setter Property="Foreground" Value="{ThemeResource DatePickerForegroundThemeBrush}"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DatePicker">
            <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 DatePickerHeaderForegroundThemeBrush}"
                                      Margin="{ThemeResource DatePickerHeaderThemeMargin}"
                                      FlowDirection="{TemplateBinding FlowDirection}"
                                      Content="{TemplateBinding Header}"
                                      ContentTemplate="{TemplateBinding HeaderTemplate}"
                                      FontWeight="{ThemeResource DatePickerHeaderThemeFontWeight}" />
                    <StackPanel Grid.Row="1" Orientation="{TemplateBinding Orientation}">
                        <Border x:Name="FirstPickerHost">
                            <ComboBox x:Name="DayPicker" 
                                MinWidth="{ThemeResource DatePickerSelectorThemeMinWidth}"
                                FontWeight="{TemplateBinding FontWeight}"
                                FontSize="{TemplateBinding FontSize}"
                                FontFamily="{TemplateBinding FontFamily}"
                                Foreground="{TemplateBinding Foreground}"/>
                        </Border>
                        <Rectangle x:Name="FirstPickerSpacing"
                             Width="{ThemeResource DatePickerSpacingThemeWidth}"
                             Height="{ThemeResource DatePickerSpacingThemeHeight}"/>
                        <Border x:Name="SecondPickerHost">
                            <ComboBox x:Name="MonthPicker"
                                MinWidth="{ThemeResource DatePickerSelectorThemeMinWidth}"
                                FontWeight="{TemplateBinding FontWeight}"
                                FontSize="{TemplateBinding FontSize}"
                                FontFamily="{TemplateBinding FontFamily}"
                                Foreground="{TemplateBinding Foreground}"/>
                        </Border>
                        <Rectangle x:Name="SecondPickerSpacing"
                             Width="{ThemeResource DatePickerSpacingThemeWidth}"
                             Height="{ThemeResource DatePickerSpacingThemeHeight}"/>
                        <Border x:Name="ThirdPickerHost">
                             <ComboBox x:Name="YearPicker"
                                 MinWidth="{ThemeResource DatePickerSelectorThemeMinWidth}"
                                 FontWeight="{TemplateBinding FontWeight}"
                                 FontSize="{TemplateBinding FontSize}"
                                 FontFamily="{TemplateBinding FontFamily}"
                                 Foreground="{TemplateBinding Foreground}"/>
                        </Border>
                    </StackPanel>
                </Grid>
            </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>