Silverlight Listbox binding to itemssource does not work

by 31. January 2011 20:25

  Or at least so I thought as I spent a few hours trying to make it work.

What made this issue particularly interesting is that it works/worked on the Windows Phone platform; my http://passwordmgr.codeplex.com/ open source project shares the same exact source code for the Desktop, Silverlight and Phone environments.   As with the Phone application, my presenter populated the ViewModel with data and all looked well.   To further complicate matters my other control bindings (to the SelectedUserProfile) were working - only the ListBox.ItemsSource was not working...

I had just completed the Phone UI work (having no issues) and started working on the Silverlight version of the UserProfileView.xaml view and for the life of me I could not get the ListBox.ItemsSource to work unless I assigned it programmatically!

Turns out that, unlike the Phone (and perhaps Desktop??? I'll find out when I'm done with the Silverlight UI), the Silverlight ItemsSource binding does not work if you bind to an ObservableCollection<yourtype> list WHEN IT IS NULL at the time of binding!  The following highlighted code fixed my problem and it now works as expected.

Notice

Blog videos and references to CodePlex projects are no longer valid