Whenever you worked with data binding, the first thing you need is a data source. We are going to work with a data inspector, which is below the files inspector. There are two types of data sources that when this presentation foundation recognizes XML data sources and CLR object data sources.
We are going to work with XML data source so I am going to click the button. A dialog comes up asking for the information from the XML data source. I am going to name this data source. In this case, I am going to name it product list.
I also need to specify a URL for my XML data. I am going to click the browse button and in the project folder directory, under lesson five, you are going to find the products XML file. I am going to press okay and now in data inspector, the product list in my sections is the first node in the XML file was displayed. I am going to look in my XML document for a moment and you will see under the resources for the Window, the XML data provider has been created.
However, if I scroll to the right, you will see that the source continues a full path to my XML document. This would just work just fine so long as I was working on my machine but if I try to give this to somebody else, they would not be able to use it unless they have exact record structure. I am going to go back to the design space and I am going to delete that data source because that is not what I want.
When I press the subtract data, blend asks me if I want to delete the data source. In this case, I do. If you want to have your data source local to your project, the way to do that is to first add it to your project. We have added project files before so I am going to right click on my project and add an existing item. I am once again go to my desktop, they are on my project files, part one in lesson five and select my XML file.
Now, when I add my XML, I am going to name it again, product list but when I add the URL I am just going to type products.xml. Since I am not specifying a path in this XML document exists in my project, it will be connected to the XML file locally in the project.
Now, when I looked in this XML, you will see that the source simply says products.xml. This means that the XML file will be local and I will have direct access to it. In the data inspector, let us take a look at what I have. I have my product listing a source and under it, I know the name sections. To understand what this means, let us take a look at what the parts of the XML file actually looks like.
I am going to right click it and choose edit externally. This would bring up whatever editor you currently have configured for XML files. In my case, I have got no path. In my XML file, the first note is sections then extras and then a group of extra regions. Each extra region has a name, description and image and a price.
Now, when I closed this I can expand sections and you will see extras and extra array. The extra array means that there are multiple nodes of the name extra inside my XML file. If I expand that node, you will see the description, image, name and price that each extra had with it. The scheme for the XML data source was inferred by blend. It looked in the XML file and figured out all of the nodes and gave it its best guess.
Now that I have my list, I want to create a control so that my user can choose one of the extra by items. I am going to click and drag the extra array on to my art board. When I release a menu with several options comes up, I could bind my extra array directly to the grid or I could create a new control, the combo box items, controls and so on to represent the extra. I am going to choose a list box.
The next dialog that comes is asking what property of the list box I want to bind the extra to. All this is asking is which property I want to connect to my data. For list boxes in most cases, you want to connect the item source. I am going to press okay.
Transcription by:
Scribe4you Transcription Services