How to bind XML file as collection of object in Silverlight using WCF service Introduction: Binding to a single object is straight forward, but practically we are more interested in binding to a collection object say like, all employee in a table. Dependency property supports the single value binding, so binding to collection of object had to be dealt with little more sophistication. Any control which support list of items is derived from items control so to support collection binding, itemscontrol class defines some properties. What are these properties? 1) ItemsSource: it point to collection which has all the objects that will be shown in the list 2) ItemTemplate: it provides the datatemplate that will be used to create the visual appearance of each item. 3) ItemsPanel: It provides a template that will be used create the layout container that holds all the items in the list. 4) DisplayMem berPath: it identifies the property that will be used to create the display text for each item. Ok, so let us create a sample project to demonstrate binding of collection object. Step 1: Create a Silverlight application project let’s say “CollectionBindingByService” Step2: Add an xml file for data storage to CollectionBindingByService.Web project and name is store.xml.
13
Embed
How to bind XML file as collection of object in Silverlight
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
How to bind XML file as collection of object in Silverlight using WCF service
Introduction: Binding to a single object is straight forward, but practically we are more interested in
binding to a collection object say like, all employee in a table. Dependency property supports the
single value binding, so binding to collection of object had to be dealt with little more sophistication.
Any control which support list of items is derived from items control so to support collection binding,
itemscontrol class defines some properties.
What are these properties?
1) ItemsSource: it point to collection which has all the objects that will be shown in the list
2) ItemTemplate: it provides the datatemplate that will be used to create the visual appearance of
each item.
3) ItemsPanel: It provides a template that will be used create the layout container that holds all the
items in the list.
4) DisplayMem berPath: it identifies the property that will be used to create the display text for each
item.
Ok, so let us create a sample project to demonstrate binding of collection object.
Step 1: Create a Silverlight application project let’s say “CollectionBindingByService”
Step2: Add an xml file for data storage to CollectionBindingByService.Web project and name is
store.xml.
Step 3: I have inserted some data into it with data nodes like below ;
<Products>
<ProductID>355</ProductID>
<CategoryID>16</CategoryID>
<ModelNumber>RU007</ModelNumber>
<ModelName>Rain Racer 2000</ModelName>
<ProductImage>image.gif</ProductImage>
<UnitCost>1499.9900</UnitCost>
<Description>Looks like an ordinary bumbershoot, but don't be fooled!
Simply place Rain Racer's tip on the ground and press the release latch.
Within seconds, this ordinary rain umbrella converts into a two-wheeled gas-
powered mini-scooter. Goes from 0 to 60 in 7.5 seconds - even in a driving
rain! Comes in black, blue, and candy-apple red.</Description>
<CategoryID1>16</CategoryID1>
<CategoryName>Travel</CategoryName>
</Products>
Step 4: Add a WCF service svc file. Name is StoreDb.svc
Step 5: Now add a class say Product.cs where we wil define our property.
Below is code of our product class with variables and property declared . note we have inherited our