I’m continuing the struggle with Silverlight, and I’d like to share my probably worst experience with you. I’d wanted to make a data-driven app in Silverlight recently, but it took a complete day. All I wanted was the binding of a MS SQL table to a Silverlight DataGrid. Because SL doesn’t support System.Data (which made me cry at the first place), I needed a workaround for this one. Then I found the template Silverlight-enabled WCF service, and it was love in the first sight, I thought. To bind a table (one-way binding, of course) in Silverlight is relatively easy. Create a service, set a reference on it, set it as the ItemSource property of the DataGrid. In code:
WebServiceSoapClient client = new WebServiceSoapClient();
client.GetCustomersCompleted += new EventHandler<GetCustomersCompletedEventArgs>(client_CustomersCompleted);
void client_CustomersCompleted(object sender, GetCustomersCompletedEventArgs e)
dataGrid1.ItemsSource = e.Result;
Easy as that.