How to add focus style to editable ComboBox in WPF

I looked at the following example on how the ComboBox style is, but I could not create the focus effect when entering the editable combo box. Whenever a ComboBox receives focus, it should go into edit mode, and the component should have a focus style.

The main problem is that whenever I switch to edit mode, it is not the surrounding ComboBox that actually has focus, but the text subcomponent, and I could not create a Trigger in the text component that changes the ComboBox frame style, since I don’t I know how to refer to a parent component from a trigger.

I tried to add a ControlTemplate Trigger to a TextBox or style trigger. I tried to reference the ComboBox by name or using the TemplateBinding parameter, but with no luck. A simple example would be much appreciated.

+2
styling wpf xaml combobox
source share
3 answers

Bind IsKeyboardFocusWithin to IsDropDownOpen

 <ComboBox ItemsSource="{Binding SortedItems}" StaysOpenOnEdit="True" IsDropDownOpen="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}, Mode=OneWay}" /> 
+3
source share
  private void cmbSpecialHandling_GotFocus(object sender, RoutedEventArgs e) { Thickness th = new Thickness(2); cmbSpecialHandling.BorderThickness = th; cmbSpecialHandling.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush; } private void cmbSpecialHandling_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { Thickness th = new Thickness(2); cmbSpecialHandling.BorderThickness = th; cmbSpecialHandling.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush; } private void cmbSpecialHandling_LostFocus(object sender, RoutedEventArgs e) { cmbSpecialHandling.BorderBrush = Brushes.Transparent; } 
+1
source share

Set the border brush with the list in Gotfocus and make it transparent with the lost focus:

 private void comboBox_GotFocus(object sender, RoutedEventArgs e) { Thickness th = new Thickness(2); comboBox.BorderThickness = th; comboBox.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush; or comboBox.BorderBrush = Brushes.Green; } private void comboBox_LostFocus(object sender, RoutedEventArgs e) { comboBox.BorderBrush = Brushes.Transparent; } 
+1
source share

All Articles