J-Unleashed!

On databases, programming and more

Posts Tagged ‘xml’

Thank You, Michael Sync!

Posted by Joe on May 3, 2008

I tried out the step-by-step example by Michael Sync for getting data into a datagrid in Silverlight via webservices. I skipped some steps as I already had a database set up, and I adapted the code to my specific needs. I’m very, very glad to say, though, with very little difficulties, it worked. I did have to surmise a few things, so I’ll jot them down here.

  • You’ll need to create the ListingControl.xaml file. The easiest way would be to rename the default Page.xaml that’s created in the Silverlight project.
  • In the ListingControl.xaml file, rename the default <Grid> from “LayoutRoot” to “ListingControl”
  • Add a “Loaded” event to the <Grid> and choose the default name (ListingControl_Loaded)
  • Add a DataGrid to the ListingControl.xaml file.

Here’s the code for the XAML file:

<UserControl xmlns:my=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data”  x:Class=”SLTwo.Page”
xmlns=”http://schemas.microsoft.com/client/2007
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml
Width=”400″ Height=”300″>
<Grid x:Name=”ListingControl” Background=”White” Loaded=”ListingControl_Loaded”>
<my:DataGrid x:Name=”CustomersDataGrid” Grid.Row=”1″ Margin=”5″ AutoGenerateColumns=”True” />
</Grid>
</UserControl>

  • Note that you may have a different solution name than the example (S2WebSrv). Mine was named SLTwo, so I had to change that in the <UserControl> tag.
  • Be careful with your XML. My data had ampersands in various places, so I had to change the line of code in the RetrieveProduct method of the web service that adds the product name to the XML so it replaces “&” with “&amp;”. The XDocument.Parse method choked on the XML it was receiving, but didn’t say why. Ugh.

Phew! What a long road just to get data flowing into a Silverlight app. Glad to say, with Michael Sync’s help, that obstacle has been overcome. Now, on to better things. Maybe I’ll try hooking up NHibernate to the ASP.NET project and play around with some more interactive content.

‘Til next time!

Posted in Silverlight | Tagged: , , | 1 Comment »