WP7 difficulties binding data to listbox itemssource - won't refresh
So I have a detail page on my WP7 app that shows a listbox showing some data from my app.
In the codebehind, I set the listbox itemssource = to a collection of objects. Pretty simple so far. I also have few text boxes and a button on the same screen that lets me add to that object collection.
Ideally when I navigate to the page, it should show the contents of the collection in the listbox. If I click add, it should add another object to the collection and then refresh the listbox to show the newly updated contents.
I set the itemsSource in the onNavigatedTo event, and I set the itemsSource开发者_C百科 in my button click event as well. My button click event just pulls the text from the textbox, creates an instance of my object with the text, adds the object to the collection, and re-sets the itemsSource
The problem is, the listbox only updates when i hit the back button and re-enter the page. Setting the itemSource on my button click event doesn't seem to do anything - the listbox won't refresh.
Does anyone know how I can refresh the listbox?
If you use ObservableCollection the listbox will automatically reflect additons and deletions.
If you try to do this without ObservableCollection I've seen this will work if you set the ItemsSource to null, before reassigning the new list.
精彩评论