0

In my application I have listBox and its items source is ObservableCollection, but when I add data, this listBox won't update. In constructor i use: listBoxPersons.ItemsSource = UserContacts; and user UserContacts is static ObservableCollection, which is initialised from database and when I open the programm, it shows correct data. But when I add new item into database and in same time using same code listBoxPersons.ItemsSource = UserContacts;, then listBox won't display added item. But when I logout and login again to my application, it displays my added items.

Timo
  • 141
  • 1
  • 2
  • 6

2 Answers2

1

You literally said add new item into the database. You need to also add the item to the ObservableCollection.

paparazzo
  • 44,497
  • 23
  • 105
  • 176
0

Perhaps the problem is with the static ObservableCollection. Try it with a non-static collection.

Fly222
  • 1
  • Using non-static didn't fix my problem. Also I find that, when I use non static, it won't display added item, but when I update existing item in listbox, these changes are displayed. – Timo May 20 '12 at 12:57