I presented recently at an internal Microsoft conference here in Seattle & showed a simple OData/ADO.Net data services & Silverlight 4 data binding example. It is very rudimentary, but shows how simple it is to get up and running binding Silverlight controls to data coming from SharePoint.
For this you will need:
The resulting list should look something like this now:
Ok now for the good stuff…
Your project should now look like this:
In this example all we are going to do is drop a grid onto our Silverlight surface and bind it to the Projects data.
Now we need to issue the query to the server to retrieve the data and bind those results to the grid.
/// <summary>Page loaded event handler</summary> private void MainPage_Loaded(object sender, RoutedEventArgs e) { // this news up our data context with the URI to the ListData.svc context = new HomeDataContext(new Uri("<a href="http://chjohn3/_vti_bin/ListData.svc"">http://chjohn3/_vti_bin/ListData.svc"</a>, UriKind.Absolute)); // create the collection that we are doing to store the projects in projects = new DataServiceCollection<ProjectsItem>(); // get the view source reference from the grid projectsViewSource = (CollectionViewSource)this.Resources["projectsViewSource"]; // Define a query that returns orders for a give customer. var query = from p in context.Projects select p; // wire up the loaded event projects.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(projects_LoadCompleted); // Asynchronously load the result of the query. projects.LoadAsync(query); } private void projects_LoadCompleted(object sender, LoadCompletedEventArgs e) { // if there wasnt an error if (e.Error == null) { // load the view source with the list of projects that were returned. projectsViewSource.Source = projects; } else { MessageBox.Show(string.Format("An error has occured: {0}", e.Error.Message)); } }
Now its time to try it all out!
Congratulations. You have just built a Silverlight 4 web part that is data bound using ADO.Net Data Services to SharePoint list data!
If you want to have a poke around with the ListData.svc Service then you can try hitting some URLs directly from IE like these:
Here is a good starting point in the documentation for how this REST interface works: http://msdn.microsoft.com/en-us/library/ff521587.aspx
Thanks,
-Chris.