Listbox’s selected item property used to get/set values at runtime. In WPF you can used ViewModel to get selected item automatically to the ViewModel, that is for another article. Let’s learn how to set selected item at runtime,
- First we need to identify the element in List Item collection
- Set the property value
Getting the Item
var itt = (ListBoxItem)lstb_base.Items.Cast<ListBoxItem>().Where((s, b) => s.Content.Equals(r.M_Base)).SingleOrDefault();
Set property of SelectedItem
lstb_base.SelectedItem = itt;