I have a ListBox in a Silverlight 2.0 app that is bound to some data coming from a WCF service that is returned from Linq to Sql. The service is simplicity itself:
public List<CourseSection> GetCourseSections()
{
CoursesDataContext db = new CoursesDataContext();
return db.CourseSections.ToList();
}
Note: you have to mark your DataContext Serialization Mode as Unidirectional for the above to work (as shown)

I added a Service Reference to this from Silverlight and bound the data to a ListBox:
private void Button_Click(object sender, RoutedEventArgs e)
{
CoursesService.CourseServiceClient client = new CourseBuilder.CoursesService.CourseServiceClient();
client.GetCourseSectionsCompleted +=
new EventHandler<CourseBuilder.CoursesService.GetCourseSectionsCompletedEventArgs>(client_GetCourseSectionsCompleted);
client.GetCourseSectionsAsync();
TextBlock1.Text = "loading...";
}
void client_GetCourseSectionsCompleted(object sender, CourseBuilder.CoursesService.GetCourseSectionsCompletedEventArgs e)
{
TextBlock1.Text = "loaded " + e.Result.Count();
ListBox1.ItemsSource = e.Result;
}
Further into the code I wanted to be able to add and remove items from the ItemsSource and have the ListBox reflect that automatically. As in WPF, this will not happen unless your ItemSource is bound to an ObservableCollection or a type that implements INotifyCollectionChanged and INotifyPropertyChanged. So I needed to make that change, but how?
Turns out that you can do this easily when you create the service reference from Silverlight, by clicking the Advanced button in the service reference dialog. This will show you the following where you can map the collection and dictionary types to the types in the drop down list. Once you have selected ObservableCollection here, then changes to the ListBox ItemSource data will notify the ListBox automatically, and so show the changes to the data, without any further work from you.
Cheers
Ian