Skip to main content

Microsoft Silverlight

Answered Question Databound ListBox Update/RefreshRSS Feed

(0)

chandler.chao
chandler...

Member

Member

269 points

81 Posts

Databound ListBox Update/Refresh

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.

Chandler Chao
iStreamPlanet

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Answered Question

Re: Databound ListBox Update/Refresh

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.

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

chandler.chao
chandler...

Member

Member

269 points

81 Posts

Re: Databound ListBox Update/Refresh

So I'll chalk this up as a bug and learn not to trust SL databinding.  Oh well.  Thanks.

Chandler Chao
iStreamPlanet

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Re: Re: Databound ListBox Update/Refresh

You can trust it...just not yet... ;)

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

Margaret Parsons
Margaret...

Member

Member

84 points

12 Posts

Microsoft

Re: Re: Databound ListBox Update/Refresh

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

Margaret Parsons [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities