1
votes

I know OnPropertyChanged and OnCollectionChanged can be used to update a binding to an itemssource, but I want to try doing things manually for once.

I don't want to go through the trouble of data virtualization and it seems like it would be easier to just manually change what i want to be displayed on the screen.

however, if I add items to the listbox manually, the listbox doesn't update. I have almost no experience doing anything in WPF without binding, so I'm not even certain the support exists.

Is there a way to add items and then give the listbox an update command? or is the listbox supposed to automatically update when its items are changed?

1

1 Answers

3
votes

If using code behind you should just be able to do this:

 ListBoxItem item = new ListBoxItem();
 item.Content = "Example Text";

 listBox.Items.Add(item);

If you're using a view model you just need to make sure you call INotifyPropertyChanged on the ObservableCollection the listbox is bound to after adding an item.