WPF Get ListBoxItem from ListBox.SelectedItem using ItemContainerGenerator.ContainerFromItem

var listBoxItem = listBox.ItemContainerGenerator.ContainerFromItem(myListBox.SelectedItem) as ListBoxItem;

if (listBoxItem != null
{
     listBoxItem.Background = SystemColors.HighlightBrush;
}

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?