I have a container, such as listbox, combobox, etc., that its ItemsSource property is bound to an observable collection in my view model. When I try to add / remove elements from the collection using some method in my virtual machine, it will not be reflected in the user interface.The only way the user interface will update is if I assign a new value to the collection (i.e. Another collection with the corresponding data), which forces it to re-bind the entire collection.
Maybe I am missing / do not understand something about the problem with binding to the collection, anyway, if someone has a solution / good explanation / both options will be great. here is a sample from my view (in this case, its list)
<ListBox
Grid.Row="9"
Grid.Column="1"
Grid.ColumnSpan="3"
Width="200"
Height="200"
ItemsSource="{Binding PreSavedRecordingScheduleList,UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedPreSavedRecordingSchedule,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Display"/>
and here is my ViewModel:
private ObservableCollection<ScheduledRecordingObject> m_PreSavedRecordingScheduleList;
PreSavedRecordingScheduleList = new ObservableCollection<ScheduledRecordingObject>();
public ObservableCollection<ScheduledRecordingObject> PreSavedRecordingScheduleList
{
get
{
return m_PreSavedRecordingScheduleList;
}
set
{
m_PreSavedRecordingScheduleList = value;
OnPropertyChanged("PreSavedRecordingScheduleList");
}
}
ScheduledRecordingObject also implements INotifyPropertyChanged.
source
share