Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Databound ListBox Update/Refresh
4 replies. Latest Post by Margaret Parsons on March 11, 2008.
(0)
chandler...
Member
269 points
81 Posts
03-09-2008 4:36 PM |
This is just boggling my mind. I have a ListBox bound to and ObservableCollection<T>. <T> implements INotifyPropertyChanged. I have bound the ListBox using the ListBox.DataContext property. The initial binding works like a charm. I cannot see for the life of me how the ListBox updates itself when a property for an object in the collection changes. I have a function wired to the PropertyChangedEventHandler and that fires off perfectly when a property is changed. The data in the collection is being updated. I just cannot figure out how to refresh the ListBox to reflect this. Is is supposed to be automatic (I doubt), or is there some method to call to refresh. I have tried reassigning the DataContext with no result as well as calling UpdateLayout on the ListBox. I've also tried removing and reattaching it to the root canvas; that did not work either. I'm stumped.
swildermuth
Star
8320 points
1,546 Posts
03-10-2008 6:58 AM |
This should work but there have been issues noticed with this. Please post this on the Bugs forum so the devs can look at it. What you're doing should be enough (ObservableCollection should be enough). Also, make sure you have your binding to the DataContext using Mode=TwoWay. I don't think its two way by default, but TwoWay is also a bit bugged in the current build.
03-10-2008 6:04 PM |
So I'll chalk this up as a bug and learn not to trust SL databinding. Oh well. Thanks.
03-11-2008 6:10 AM |
You can trust it...just not yet... ;)
Margaret...
84 points
12 Posts
03-11-2008 4:38 PM |
This should work. I have a sample that uses ListBox and I'm able to update the data in the code and the ListBox updates via the binding. Can you give more details about how you are changing the data? Also, why type of object is the property that you are updating? One problem that I can think of is that not only your base class must implement INotifyPropertyChanged but all of its children must also implement it if the binding is going to know about changes that happen.
Margaret