title: How do I set combobox background colour when it gets focus
body: <p>I'm relatively new to WPF, so bear with me. </p>
  
  <p>I'm trying to set the background colour of a combo box when it receives focus. I'm setting a trigger in the control template for it's togglebutton to change colour on mouse over, and when it receives focus. Mouse over works fine, but when I tab into the combobox nothing happens until I tab a second time(It changes colour then).</p>
  
  <p>So what I want is for the background colour to change when the user first tabs in. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>&lt;SolidColorBrush x:Key="ComboBoxNormalBorderBrush" Color="Black" /&gt;
  &lt;SolidColorBrush x:Key="ComboBoxNormalBackgroundBrush" Color="#fff" /&gt;
  &lt;SolidColorBrush x:Key="ComboBoxDisabledForegroundBrush" Color="#888" /&gt;
  &lt;SolidColorBrush x:Key="ComboBoxDisabledBackgroundBrush" Color="#eee" /&gt;
  &lt;SolidColorBrush x:Key="ComboBoxDisabledBorderBrush" Color="#888" /&gt;
  
  
  
  &lt;ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate"&gt;
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition /&gt;
              &lt;ColumnDefinition Width="20" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Border 
              Grid.ColumnSpan="2"
              Name="Border"
              BorderBrush="{StaticResource ComboBoxNormalBorderBrush}" 
              CornerRadius="0" BorderThickness="0.6" 
              Background="{StaticResource YellowBrush}"&gt;
  
          &lt;/Border&gt;
          &lt;Border 
              Grid.Column="1" 
              Margin="1" 
              BorderBrush="#444" 
              Name="ButtonBorder"
              CornerRadius="0, 0, 0, 0" 
              BorderThickness="2" 
              Background="Gray" /&gt;
  
          &lt;Path Name="Arrow" Grid.Column="1" 
          Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z"
          HorizontalAlignment="Center" Fill="White"
          VerticalAlignment="Center" /&gt;
      &lt;/Grid&gt;
      &lt;ControlTemplate.Triggers&gt;
          &lt;Trigger Property="ToggleButton.IsMouseOver" Value="true"&gt;
              &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource YellowBrush1}" /&gt;
          &lt;/Trigger&gt;
          &lt;Trigger Property="ToggleButton.IsFocused" Value="True"&gt;
              &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource YellowBrush1}" /&gt;
          &lt;/Trigger&gt;
  
          &lt;Trigger Property="UIElement.IsMouseOver" Value="True"&gt;
              &lt;Setter Property="Panel.Background" TargetName="ButtonBorder" Value="DarkGray"/&gt;
          &lt;/Trigger&gt;
          &lt;Trigger Property="ToggleButton.IsChecked" Value="True"&gt;
              &lt;Setter Property="Panel.Background" TargetName="ButtonBorder" Value="LightGray"/&gt;
  
              &lt;Setter Property="Shape.Fill" TargetName="Arrow" Value="Black"/&gt;
          &lt;/Trigger&gt;
          &lt;Trigger Property="UIElement.IsEnabled" Value="False"&gt;
              &lt;Setter Property="Panel.Background" TargetName="Border" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/&gt;
              &lt;Setter Property="Panel.Background" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/&gt;
              &lt;Setter Property="Border.BorderBrush" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBorderBrush}"/&gt;
              &lt;Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/&gt;
              &lt;Setter Property="Shape.Fill" TargetName="Arrow" Value="#999"/&gt;
          &lt;/Trigger&gt;
      &lt;/ControlTemplate.Triggers&gt;
  &lt;/ControlTemplate&gt;
  
  &lt;Style TargetType="{x:Type ComboBox}"&gt;
      &lt;Setter Property="UIElement.SnapsToDevicePixels" Value="True"/&gt;
      &lt;Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/&gt;
      &lt;Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.CanContentScroll" Value="True"/&gt;
      &lt;Setter Property="TextElement.Foreground" Value="Black"/&gt;
      &lt;Setter Property="Height" Value="25"/&gt;
      &lt;Setter Property="Margin" Value="0,0,0,4"/&gt;
      &lt;Setter Property="BorderThickness" Value="2"/&gt;
      &lt;Setter Property="IsEditable" Value="False"/&gt;
      &lt;Setter Property="BorderBrush" Value="Black"/&gt;
      &lt;Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/&gt;
      &lt;Setter Property="Background" Value="{StaticResource NouvemYellowBrush}"/&gt;
      &lt;Setter Property="Control.Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="ComboBox"&gt;
                  &lt;Grid&gt;
                      &lt;ToggleButton Name="ToggleButton"
                                    ClickMode="Press" 
                                    Focusable="True"
                                    IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                                    Template="{StaticResource ComboBoxToggleButtonTemplate}"/&gt;
  
                      &lt;ContentPresenter Name="ContentSite" Margin="5, 3, 23, 3" IsHitTestVisible="False"
                            HorizontalAlignment="Left" VerticalAlignment="Center"  
                   Focusable="False"
                            Content="{TemplateBinding ComboBox.SelectionBoxItem}" 
                            ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/&gt;
  
                      &lt;TextBox Name="PART_EditableTextBox" Margin="3, 3, 23, 3"                     
                               IsReadOnly="{TemplateBinding IsReadOnly}"
                               Visibility="Hidden" Background="Transparent"
                               HorizontalAlignment="Left" VerticalAlignment="Center"
                               Focusable="False"&gt;
                          &lt;TextBox.Template&gt;
                              &lt;ControlTemplate TargetType="TextBox"&gt;
                                  &lt;Border Name="PART_ContentHost" Focusable="False"/&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/TextBox.Template&gt;
                      &lt;/TextBox&gt;
  
                      &lt;!-- Popup showing items --&gt;
                      &lt;Popup Name="Popup"
                             Placement="Bottom"
                             Focusable="False" 
                             AllowsTransparency="True"
                             IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
                             PopupAnimation="Slide"&gt;
  
                          &lt;Grid Name="DropDown" SnapsToDevicePixels="True"
                                MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
                                Focusable="False"
                                MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}"&gt;
                              &lt;Border Name="DropDownBorder" 
                                  Background="White" 
                                      Focusable="False"
                                  Margin="0, 1, 0, 0"
                                  CornerRadius="0" 
                                  BorderThickness="1" 
                                  BorderBrush="Black"/&gt;
                              &lt;ScrollViewer Margin="4" SnapsToDevicePixels="True" Focusable="False"&gt;
                                  &lt;ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" Focusable="False"/&gt;
                              &lt;/ScrollViewer&gt;
                          &lt;/Grid&gt;
                      &lt;/Popup&gt;
                  &lt;/Grid&gt;
                  &lt;ControlTemplate.Triggers&gt;
  
                      &lt;Trigger Property="ItemsControl.HasItems" Value="False"&gt;
                          &lt;Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="UIElement.IsEnabled" Value="False"&gt;
                          &lt;Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="ItemsControl.IsGrouping" Value="True"&gt;
                          &lt;Setter Property="ScrollViewer.CanContentScroll" Value="False"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="ComboBox.IsEditable" Value="True"&gt;
                          &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="False"/&gt;
                          &lt;Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/&gt;
                          &lt;Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  
  
  &lt;/Style&gt;
  </code></pre>
  
  <p>Edit: showing the relevant view</p>
  
  <p></p>
  
  <pre><code>&lt;i:Interaction.Triggers&gt;
      &lt;i:EventTrigger EventName="Loaded"&gt;
          &lt;command:EventToCommand Command="{Binding OnLoadingCommand}" PassEventArgsToCommand="True"/&gt;
      &lt;/i:EventTrigger&gt;
      &lt;i:EventTrigger EventName="Unloaded"&gt;
          &lt;command:EventToCommand Command="{Binding OnClosingCommand}" PassEventArgsToCommand="True"/&gt;
      &lt;/i:EventTrigger&gt;
  &lt;/i:Interaction.Triggers&gt;
  
  &lt;Grid&gt;
  
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="3*"/&gt;
          &lt;ColumnDefinition Width="11*"/&gt;
          &lt;ColumnDefinition Width="14*"/&gt;
          &lt;ColumnDefinition Width="14*"/&gt;
          &lt;ColumnDefinition Width="14*"/&gt;
          &lt;ColumnDefinition Width="14*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height=".2*"/&gt;
          &lt;RowDefinition Height="3.5*"/&gt;
          &lt;RowDefinition Height="8*"/&gt;
          &lt;RowDefinition Height="*"/&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;Grid x:Name="GridGlobalData" Grid.Row="1" Grid.ColumnSpan="6"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
  
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;!--left side--&gt;
          &lt;Label Content="Code _________________________________________________________________________________________________________________"/&gt;
          &lt;Label Content="Name _________________________________________________________________________________________________________________" Grid.Row="1"/&gt;
          &lt;Label Content="Business Partner Type ________________________________________________________________________" Grid.Row="2"/&gt;
          &lt;Label Content="Group _________________________________________________________________________________________________________________" Grid.Row="3"/&gt;
          &lt;Label Content="Currency ___________________________________________________________________________________________________________" Grid.Row="4"/&gt;
  
  
          &lt;TextBox x:Name="TextBoxCode" Text="{Binding PartnerCode, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1"&gt;
              &lt;TextBox.InputBindings&gt;
                  &lt;KeyBinding Command="{Binding ControlButtonCommand}" CommandParameter="Add" Key="A"  Modifiers="Control" /&gt;
                  &lt;KeyBinding Command="{Binding FindBusinessPartnerCommand}" CommandParameter="Code"  Key="Enter"/&gt;
              &lt;/TextBox.InputBindings&gt;
          &lt;/TextBox&gt;
  
          &lt;TextBox Text="{Binding PartnerName, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1"&gt;
              &lt;TextBox.InputBindings&gt;
                  &lt;KeyBinding Command="{Binding FindBusinessPartnerCommand}" CommandParameter="Name"  Key="Enter"/&gt;
              &lt;/TextBox.InputBindings&gt;
          &lt;/TextBox&gt;
          &lt;ComboBox ItemsSource="{Binding BusinessPartnerTypes}" DisplayMemberPath="Type" SelectedItem="{Binding PartnerType}" SelectedIndex="0" Grid.Column="1" Grid.Row="2"/&gt;
          &lt;ComboBox ItemsSource="{Binding BusinessPartnerGroups}" DisplayMemberPath="BPGroupName" SelectedItem="{Binding PartnerGroup}" SelectedIndex="0" Grid.Column="1" Grid.Row="3"/&gt;
          &lt;ComboBox ItemsSource="{Binding BusinessPartnerCurrencies}" DisplayMemberPath="Name" SelectedItem="{Binding PartnerCurrency}" SelectedIndex="0" Grid.Column="1" Grid.Row="4"/&gt;
  
  
          &lt;!--right side--&gt;
          &lt;Label Content="Display Currency _________________________________________________________________________________________________________________" Grid.Column="3" /&gt;
          &lt;Label Content="Invoices _________________________________________________________________________________________________________________" Grid.Column="3" Grid.Row="1"/&gt;
          &lt;Label Content="Deliveries _________________________________________________________________________________________________________________" Grid.Column="3" Grid.Row="2"/&gt;
          &lt;Label Content="Orders _________________________________________________________________________________________________________________" Grid.Column="3" Grid.Row="3"/&gt;
          &lt;ComboBox ItemsSource="{Binding BusinessPartnerCurrencies}" DisplayMemberPath="Name" SelectedItem="{Binding DisplayCurrency}" Style="{StaticResource StyleComboBoxReadonly}" SelectedIndex="0" Grid.Column="4"/&gt;
          &lt;TextBox Style="{StaticResource StyleTextBoxNonEditable}" Grid.Column="4" Grid.Row="1"/&gt;
          &lt;TextBox Style="{StaticResource StyleTextBoxNonEditable}" Grid.Column="4" Grid.Row="2"/&gt;
          &lt;TextBox Style="{StaticResource StyleTextBoxNonEditable}" Grid.Column="4" Grid.Row="3"/&gt;
  
      &lt;/Grid&gt;
  
      &lt;TabControl SelectedIndex="{Binding SelectedPartnerView}" Grid.Row="2" Grid.ColumnSpan="6" &gt;
          &lt;TabItem Header="General"&gt;
              &lt;BusinessPartner:BPGeneralView /&gt;    
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Contacts"&gt;
              &lt;BusinessPartner:BPContactView /&gt;
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Addresses"&gt;
              &lt;BusinessPartner:BPAddressesView /&gt;
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Payment Terms"&gt; 
              &lt;BusinessPartner:BPPaymentTerms /&gt;
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Properties"&gt;
              &lt;BusinessPartner:BPPropertiesView /&gt;
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Remarks"&gt;
              &lt;BusinessPartner:BPRemarksView /&gt;
          &lt;/TabItem&gt;
  
          &lt;TabItem Header="Attachments"&gt;
              &lt;BusinessPartner:BPAttachmentsView /&gt;
          &lt;/TabItem&gt;
  
      &lt;/TabControl&gt;
  
      &lt;Grid x:Name="GridCrontrolButtons" Grid.Row="3" Grid.ColumnSpan="6"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="7*"/&gt;
              &lt;RowDefinition Height="*"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;data:CrudView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>