Clyde Eisenbeis

Clyde Eisenbeis

  • 1.7k
  • 63
  • 11.6k

How do change the Background color on one ListBox item? - Continued #2

Mar 13 2024 10:52 PM

C# wpf --- This is a "continuation" of c-sharpcorner.com/forums/how-do-change-the-background-color-on-one-listbox-item-continued.

When I highlight one ListBox item,

gLBxEpidemicSequence.SelectedIndex = iIndex;

the background is Gray.  How do I change the background color?

---

The response, by Abhishek Yadav, was "you can do the following:"

gLBxEpidemicSequence.SelectionBackground = Brushes.Blue;

"This will change the background color of the selected item to blue."

---

When I use SelectionBackground

gLBxEpidemicSequence.SelectionBackground = Brushes.Blue;

the error message is:

'ListBox' does not contain a definition for 'SelectionBackground' and no
accessible extension method 'SelectionBackground' accepting a first argument
of type 'ListBox' could be found (are you missing a using directive or an
assembly reference?)

Please advise.

 


Answers (3)