R – ListBox selected index color wpf

listboxselectedindexwpfwpf-controls

I am just starting with WPF and I have this ListBox that displays an attribute
from a class I made. I have to programmatically change the selected index, when I do something like:

ListBox1.SelectedIndex = 4; 

the SelectedIndex is changed and highlighted gray, but if I click on it, the selected index is blue. Is there something else i need to do to have both behave the same?

Best Solution

Sounds like the focus is not on the ListBox. Try ListBox1.Focus() after changing the SelectedIndex.

Related Question