fast and furios Silverlight Databinding with Gridview and embedded XML Data Resources

 

I am currently writing a Silverlight 2.0 course. I always try to focus on the problem and reduce the code overhead. For my Module “Databinding with Silverlight 2.0” I try to include the data as raw xml. For that purpose I include a northwind.xml file as data source into the project to focus on datagrid details. The most important part is, to set the build action to content, which ends up in including the xml file into the xap package.

 image

Then you can load the xml directly by xdocument.load. I had problems when xml is not valif or have exoctic encoding ( windows-1252). Rest is a little bit LINQ to create collection of northwinddata objects.

 

 
 Dim myxml = XDocument.Load("northwind.xml")
 Dim xmlquery1 = From x In myxml.Descendants("row") _
               Select New northwinddata With _
               {.customerid = x.@CustomerID, _
                .companyname = x.@CompanyName}
 dataGrid1.ItemsSource = xmlquery1

 

Finally the result

image

Interesting note at the bottom line. It is also possible to load the xaml content.

 Dim myxml  XDocument.Load("/gird1;component/page.xaml")
Published Tuesday, July 29, 2008 8:32 PM by preishuber
Filed under: ,

Comments

# re: fast and furios Silverlight Databinding with Gridview and embedded XML Data Resources

Wednesday, August 20, 2008 6:02 AM by mayurpanchal

good one

Leave a Comment

(required) 
(required) 
(optional)
(required)