ComboBox styles and templates

Applies to Windows and Windows Phone

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

Visual states

These are the VisualStates defined in the control's default style.

VisualState nameVisualStateGroup nameDescription
NormalCommonStatesThe default state.
PointerOverCommonStatesThe pointer is positioned over the control.
PressedCommonStatesThe control is pressed.
DisabledCommonStatesThe control is disabled.
CheckedCheckStates IsChecked is true.
UncheckedCheckStates IsChecked is false.
IndeterminateCheckStates IsThreeState is true, and IsChecked is null.
FocusedFocusStatesThe control has focus.
FocusedPressedFocusStatesThe control has focus and is pressed.
UnfocusedFocusStatesThe control doesn't have focus.
PointerFocusedFocusStatesThe control has focus obtained through a pointer action.
FocusedDropDownFocusStatesThe drop-down for the ComboBox has focus.
OpenedDropDownStatesThe drop-down for the ComboBox is open.
ClosedDropDownStatesThe drop-down for the ComboBox is closed.

 

For more info about focus states, see Control.FocusState.

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="ComboBoxArrowDisabledForegroundThemeBrush" Color="#66FFFFFF" />
<SolidColorBrush x:Key="ComboBoxArrowForegroundThemeBrush" Color="#FF000000" />   
<SolidColorBrush x:Key="ComboBoxArrowPressedForegroundThemeBrush" Color="#FF000000" />   
<SolidColorBrush x:Key="ComboBoxBackgroundThemeBrush" Color="#CCFFFFFF" />
<SolidColorBrush x:Key="ComboBoxBorderThemeBrush" Color="#CCFFFFFF" />
<SolidColorBrush x:Key="ComboBoxDisabledBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ComboBoxDisabledBorderThemeBrush" Color="#66FFFFFF" />
<SolidColorBrush x:Key="ComboBoxDisabledForegroundThemeBrush" Color="#66FFFFFF" />
<SolidColorBrush x:Key="ComboBoxFocusedBackgroundThemeBrush" Color="White" />
<SolidColorBrush x:Key="ComboBoxFocusedBorderThemeBrush" Color="White" />
<SolidColorBrush x:Key="ComboBoxFocusedForegroundThemeBrush" Color="White" />
<SolidColorBrush x:Key="ComboBoxForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxHeaderForegroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPlaceholderTextForegroundThemeBrush" Color="#88000000" />
<SolidColorBrush x:Key="ComboBoxPointerOverBackgroundThemeBrush" Color="#DEFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPointerOverBorderThemeBrush" Color="#DEFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPopupBackgroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPopupBorderThemeBrush" Color="#FF212121" />
<SolidColorBrush x:Key="ComboBoxPopupForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxPressedBackgroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPressedBorderThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPressedHighlightThemeBrush" Color="#FFD3D3D3" />
<SolidColorBrush x:Key="ComboBoxPressedForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxSelectedBackgroundThemeBrush" Color="#FF4617B4" />
<SolidColorBrush x:Key="ComboBoxSelectedPointerOverBackgroundThemeBrush" Color="#FF5F37BE" />

Light theme brushes

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


<SolidColorBrush x:Key="ComboBoxArrowDisabledForegroundThemeBrush" Color="#66000000" />
<SolidColorBrush x:Key="ComboBoxArrowForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxArrowPressedForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxBackgroundThemeBrush" Color="#CCFFFFFF" />
<SolidColorBrush x:Key="ComboBoxBorderThemeBrush" Color="#45000000" />
<SolidColorBrush x:Key="ComboBoxDisabledBackgroundThemeBrush" Color="#66CACACA" />
<SolidColorBrush x:Key="ComboBoxDisabledBorderThemeBrush" Color="#26000000" />
<SolidColorBrush x:Key="ComboBoxDisabledForegroundThemeBrush" Color="#66000000" />
<SolidColorBrush x:Key="ComboBoxFocusedBackgroundThemeBrush" Color="White" />
<SolidColorBrush x:Key="ComboBoxFocusedBorderThemeBrush" Color="#70000000" />
<SolidColorBrush x:Key="ComboBoxFocusedForegroundThemeBrush" Color="White" />
<SolidColorBrush x:Key="ComboBoxForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxHeaderForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxPlaceholderTextForegroundThemeBrush" Color="#88000000" />
<SolidColorBrush x:Key="ComboBoxPointerOverBackgroundThemeBrush" Color="#DEFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPointerOverBorderThemeBrush" Color="#70000000" />
<SolidColorBrush x:Key="ComboBoxPopupBackgroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPopupBorderThemeBrush" Color="#FF212121" />
<SolidColorBrush x:Key="ComboBoxPopupForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxPressedBackgroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ComboBoxPressedBorderThemeBrush" Color="#A3000000" />
<SolidColorBrush x:Key="ComboBoxPressedHighlightThemeBrush" Color="#FFD3D3D3" />
<SolidColorBrush x:Key="ComboBoxPressedForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="ComboBoxSelectedBackgroundThemeBrush" Color="#FF4617B4" />
<SolidColorBrush x:Key="ComboBoxSelectedPointerOverBackgroundThemeBrush" Color="#FF5F37BE" /> 

Other resources


<x:Double x:Key="ComboBoxThemeMinWidth">64</x:Double>
<x:Double x:Key="ComboBoxPopupThemeMinWidth">80</x:Double>
<x:Double x:Key="ComboBoxArrowThemeFontSize">21</x:Double>
<Thickness x:Key="ComboBoxBorderThemeThickness">2</Thickness>
<Thickness x:Key="ComboBoxHeaderThemeMargin">0,0,0,6</Thickness>
<Thickness x:Key="ComboBoxPopupBorderThemeThickness">2</Thickness>
<FontWeight x:Key="ComboBoxHeaderThemeFontWeight">SemiLight</FontWeight>
<FontWeight x:Key="ComboBoxPlaceholderTextThemeFontWeight">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="SymbolThemeFontFamily">Segoe UI Symbol</FontFamily>
<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.ComboBox -->
<Style TargetType="ComboBox">
    <Setter Property="Padding" Value="8,0" />
    <Setter Property="MinWidth" Value="{ThemeResource ComboBoxThemeMinWidth}" />
    <Setter Property="Foreground" Value="{ThemeResource ComboBoxForegroundThemeBrush}" />
    <Setter Property="Background" Value="{ThemeResource ComboBoxBackgroundThemeBrush}" />
    <Setter Property="BorderBrush" Value="{ThemeResource ComboBoxBorderThemeBrush}" />
    <Setter Property="BorderThickness" Value="{ThemeResource ComboBoxBorderThemeThickness}" />
    <Setter Property="TabNavigation" Value="Once" />
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
    <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True" />
    <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
    <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <CarouselPanel />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="32" />
                    </Grid.ColumnDefinitions>
                    
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="PointerOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPointerOverBackgroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPointerOverBorderThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Highlight"
                                                                   Storyboard.TargetProperty="Fill">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxSelectedPointerOverBackgroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBackgroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBorderThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation Storyboard.TargetName="PressedBackground"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropDownGlyph"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowPressedForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBackgroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropDownGlyph"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowDisabledForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="FocusStates">
                            <VisualState x:Name="Focused">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="HighlightBackground"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                    <DoubleAnimation Storyboard.TargetName="Highlight"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxFocusedForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="FocusedPressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Highlight"
                                                                   Storyboard.TargetProperty="Fill">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedHighlightThemeBrush}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unfocused" />
                            <VisualState x:Name="PointerFocused" />
                            <VisualState x:Name="FocusedDropDown">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PopupBorder"
                                                                   Storyboard.TargetProperty="Visibility"
                                                                   Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="DropDownStates">
                            <VisualState x:Name="Opened">
                                <Storyboard>
                                    <SplitOpenThemeAnimation
                                      OpenedTargetName="PopupBorder"
                                      ContentTargetName="ScrollViewer"
                                      ClosedTargetName="ContentPresenter"
                                      ContentTranslationOffset="0"
                                      OffsetFromCenter="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOffset}"
                                      OpenedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOpenedHeight}"
                                      ClosedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownClosedHeight}" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Closed">
                                <Storyboard>
                                    <SplitCloseThemeAnimation
                                      OpenedTargetName="PopupBorder"
                                      ContentTargetName="ScrollViewer"
                                      ClosedTargetName="ContentPresenter"
                                      ContentTranslationOffset="40"
                                      OffsetFromCenter="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOffset}"
                                      ContentTranslationDirection="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.SelectedItemDirection}"
                                      OpenedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOpenedHeight}"
                                      ClosedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownClosedHeight}" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                    <ContentPresenter x:Name="HeaderContentPresenter"
                                      Foreground="{ThemeResource ComboBoxHeaderForegroundThemeBrush}"
                                      Margin="{ThemeResource ComboBoxHeaderThemeMargin}"
                                      FlowDirection="{TemplateBinding FlowDirection}"
                                      FontWeight="{ThemeResource ComboBoxHeaderThemeFontWeight}"
                                      Visibility="Collapsed"  
                                      Content="{TemplateBinding Header}"
                                      ContentTemplate="{TemplateBinding HeaderTemplate}" />
                        
                    <Border x:Name="Background"
                            Grid.Row="1"
                            Grid.ColumnSpan="2"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" />
                    <Rectangle x:Name="PressedBackground"
                               Grid.Row="1"
                               Fill="{ThemeResource ComboBoxPressedHighlightThemeBrush}"
                               Margin="{TemplateBinding BorderThickness}"
                               Opacity="0" />
                    <Border x:Name="HighlightBackground"
                            Grid.Row="1"
                            Grid.ColumnSpan="2"
                            Background="{ThemeResource ComboBoxFocusedBackgroundThemeBrush}"
                            BorderBrush="{ThemeResource ComboBoxFocusedBorderThemeBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Opacity="0" />
                    <Rectangle x:Name="Highlight"
                               Grid.Row="1"
                               Fill="{ThemeResource ComboBoxSelectedBackgroundThemeBrush}"
                               Margin="{TemplateBinding BorderThickness}"
                               Opacity="0" />
                    <ContentPresenter x:Name="ContentPresenter"
                                      Grid.Row="1"
                                      Margin="{TemplateBinding Padding}"
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                        <TextBlock x:Name="PlaceholderTextBlock"
                                   Text="{TemplateBinding PlaceholderText}"
                                   Foreground="{ThemeResource ComboBoxPlaceholderTextForegroundThemeBrush}"
                                   FontWeight="{ThemeResource ComboBoxPlaceholderTextThemeFontWeight}"/>
                    </ContentPresenter>
                    <TextBlock x:Name="DropDownGlyph"
                               Text="&#57361;"
                               Grid.Row="1"
                               Grid.Column="1"
                               IsHitTestVisible="False"
                               Margin="0,0,6,4"
                               Foreground="{ThemeResource ComboBoxArrowForegroundThemeBrush}"
                               FontWeight="Bold"
                               FontSize="{ThemeResource ComboBoxArrowThemeFontSize}"
                               FontFamily="{ThemeResource SymbolThemeFontFamily}"
                               HorizontalAlignment="Right"
                               VerticalAlignment="Center"
                               AutomationProperties.AccessibilityView="Raw"/>
                    <Popup x:Name="Popup">
                        <Border x:Name="PopupBorder"
                                Background="{ThemeResource ComboBoxPopupBackgroundThemeBrush}"
                                BorderBrush="{ThemeResource ComboBoxPopupBorderThemeBrush}"
                                BorderThickness="{ThemeResource ComboBoxPopupBorderThemeThickness}"
                                HorizontalAlignment="Stretch">
                            <ScrollViewer x:Name="ScrollViewer" Foreground="{ThemeResource ComboBoxPopupForegroundThemeBrush}"
                                            MinWidth="{ThemeResource ComboBoxPopupThemeMinWidth}"
                                            VerticalSnapPointsType="OptionalSingle"
                                            VerticalSnapPointsAlignment="Near"
                                            HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                            HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                            VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                            VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                            IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                            IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                            IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                            BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
                                            ZoomMode="Disabled"
                                            AutomationProperties.AccessibilityView="Raw">
                                <ItemsPresenter/>
                            </ScrollViewer>
                        </Border>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

 

 

Show:
© 2014 Microsoft