Relative Content

Tag Archive for c#wpfuser-interfacelistboxobservablecollection

ObservableCollection stopped updating consistently with WPF Listbox

I am using WPF and have a Listbox that I have bound in the code behind to an ObservableCollection. It is displayed in multiple views and has worked perfectly (adding/removing, & staying in sync between views) until I tried to add an icon to the list items. Now it isn’t even consistently adding items to the listbox when they are added to the ObservableCollection. What I was attempting to change was instead of just displaying the name of the item in the listbox, when the items ‘monitoring’ attribtute is true I want it to display an image beside the name and to remove this image when the monitoring attribute is false. This part is working, the icon appears and is removed correctly. To get this icon to display correctly I modified my xaml by adding a ListBox.ItemTemplate->DataTemplate as seen below.