Search code examples
c#wpflistboxbackground-color

How to change a listbox unselected item colour from code behind


I have to create listBox via code behind. After that I have to change the colour that the selected item has when the listbox is not selected. I have found that solution but am not able to render it via code behind.

enter image description here

Thank you


Solution

  • Very easy if it's ok for you overriding the windows colour on the listbox

    listBox1.Resources[SystemColors.InactiveSelectionHighlightBrushKey] = Brushes.Blue;
    

    I picked your rgb colour so to be precise it's:

    listBox1.Resources[SystemColors.InactiveSelectionHighlightBrushKey] = new SolidColorBrush(Color.FromArgb(255, (byte)51, (byte)153, (byte)255));