Change the background color of a WPF editable ComboBox programmatically

Master_T

I'm trying to dynamically change the background color of an editable ComboBox at runtime, using code. In particular, I want to change the background of the editable TextBox that is part of the ComboBox.

There are several answers about this on SO, like this one:

WPF change the background color of an edittable combobox in code

however, the problem is that they're all based on XAML and editing default templates. I don't want to do that, I'm searching for a generic solution that works with just code.

Is it possible? I tried the solution that seems obvious:

TextBox textBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox);
textBox.Background = Brushes.Yellow;

But this does absolutely nothing. What am I missing?

Nitin

This is how you can do it

<ComboBox Loaded="MyCombo_OnLoaded"  x:Name="myCombo" IsEditable="True"></ComboBox>

private void MyCombo_OnLoaded(object sender, RoutedEventArgs e)
{
      var textbox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);
      if (textbox!= null)
      {
           var parent = (Border)textbox.Parent;
           parent.Background = Brushes.Yellow;
       }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Change the background color of CardView programmatically

From Dev

Change Button Background color on EventTrigger in WPF

From Dev

Change the background color of the layout programmatically

From Dev

WPF Change Background color of a Combobox

From Dev

How to apply spell checking for Editable ComboBox in WPF

From Dev

JavaFX 8 - How to change the color of the prompt text of a NOT editable combobox via CSS?

From Dev

Set border color of editable ComboBox on focus

From Dev

How to change background color in ttk.Combobox's listview?

From Dev

How to change ImageButton drawable color when used as background programmatically?

From Dev

How would I programmatically change the background color of a cell

From Dev

WPF: How to change TransitioningContentControl background color?

From Dev

WPF change cell background color based on content

From Dev

How change the background color of the dropdown panel of Combobox

From Dev

Change ListBox Item Background color programmatically

From Dev

WPF combobox hover change color template

From Dev

Change color of Selected-Unfocused ComboBox Item in wpf

From Dev

Use ComboBox to change the background color of panel

From Dev

Change BackGround Color from database(WPF)?

From Dev

WPF Editable Combobox does not change SelectedValue while typing

From Dev

WPF Exiting "Dropped" Combobox, Items no longer editable?

From Dev

how can i set the background color of the TextBox in an editable ComboBox?

From Dev

Change border color of Combobox in WPF

From Dev

How to change programmatically the background color of in tvOS in Swift?

From Dev

WPF Editable Listview with an editable ComboBox

From Dev

Change the background color of a WPF editable ComboBox programmatically

From Dev

WPF change cell background color based on content

From Dev

How to change background Color of Navigationbar programmatically in Xamarin?

From Dev

How to change a background shape's color programmatically

From Dev

WPF Change focused TextBox background color

Related Related

  1. 1

    Change the background color of CardView programmatically

  2. 2

    Change Button Background color on EventTrigger in WPF

  3. 3

    Change the background color of the layout programmatically

  4. 4

    WPF Change Background color of a Combobox

  5. 5

    How to apply spell checking for Editable ComboBox in WPF

  6. 6

    JavaFX 8 - How to change the color of the prompt text of a NOT editable combobox via CSS?

  7. 7

    Set border color of editable ComboBox on focus

  8. 8

    How to change background color in ttk.Combobox's listview?

  9. 9

    How to change ImageButton drawable color when used as background programmatically?

  10. 10

    How would I programmatically change the background color of a cell

  11. 11

    WPF: How to change TransitioningContentControl background color?

  12. 12

    WPF change cell background color based on content

  13. 13

    How change the background color of the dropdown panel of Combobox

  14. 14

    Change ListBox Item Background color programmatically

  15. 15

    WPF combobox hover change color template

  16. 16

    Change color of Selected-Unfocused ComboBox Item in wpf

  17. 17

    Use ComboBox to change the background color of panel

  18. 18

    Change BackGround Color from database(WPF)?

  19. 19

    WPF Editable Combobox does not change SelectedValue while typing

  20. 20

    WPF Exiting "Dropped" Combobox, Items no longer editable?

  21. 21

    how can i set the background color of the TextBox in an editable ComboBox?

  22. 22

    Change border color of Combobox in WPF

  23. 23

    How to change programmatically the background color of in tvOS in Swift?

  24. 24

    WPF Editable Listview with an editable ComboBox

  25. 25

    Change the background color of a WPF editable ComboBox programmatically

  26. 26

    WPF change cell background color based on content

  27. 27

    How to change background Color of Navigationbar programmatically in Xamarin?

  28. 28

    How to change a background shape's color programmatically

  29. 29

    WPF Change focused TextBox background color

HotTag

Archive