Add or remove a data source
You can add data sources directly to your Microsoft® Expression Blend™ project or you can link to them at an external location. Data sources are effectively project resources, so after you add them to your project, you will see a list of the data source files within the Resources panel.
To add an XML data source
An XML data source can be a local XML file or an XML file on a remote Web server. For an example of using a remote XML file, see the topic Creating an RSS news reader.
- Under Data in the Project panel, click the +XML button.
- In the Add XML Data Source dialog box, enter the name in the Connection Name field for the data connection that you want to create.
- In the URL for XML data field, enter a URL for your XML
data file, or click Browse to locate a local
If you are using a local XML file, we recommended that you add the XML file to your project so that the file will be built into the application. This ensures that your application will work when you deploy it. Alternatively, you can deploy the application and the XML file together, as long as the path to the XML file remains the same.
- You can optionally click the expander to enter additional information
for your data source, such as an XPath definition.
Specifying an XPath definition narrows down the data that you bring in from the data source, by identifying specific nodes in the XML data that you want. For more information about using XPath, see the topics XPath Syntax and How to: Bind to XML Data Using an XMLDataProvider and XPath Queries on MSDN.
- Click OK. Notice that the Data section of the Project panel is now populated with the data that is parsed from the XML file. The data type for each node in the data source is listed in parentheses. You can now bind objects in your project to the XML data.
To add a CLR Object data source
In a team production environment, a developer could provide a common language runtime (CLR) data source to a designer so that the designer could bind to data in their Expression Blend project in any way that they chose. A CLR data source is implemented in a class library assembly (.dll). The implementation populates a data table or data set from a database (such as an SQL database), and converts the data to an ObservableCollection so that Expression Blend (or any application that uses Windows Presentation Foundation) can bind to the data. For an example of a class library that is written in C# and an Expression Blend project that binds to the resulting data, see Create a CLR object data source.
- In the Project menu, click Add Reference
The Add Reference dialog box opens.
- Browse to the assembly (.dll) that implements a CLR data
source. Select the assembly and then click Open.
The .dll file is added to the Reference node under Files in the Project panel.
- Under Data in the Project
panel, click the +CLR Object
The Add CLR Object Data Source dialog box opens.
- In the Data Source Name field, enter a name for this data source or leave it as the default (CLRObjectDataSource).
- Under Select the class to create an instance of, expand the name of your assembly, select the CLR object, and then
Notice that the Data section of the Project panel is now populated with the data that is parsed from the CLR data source. The data type for each node in the data source is listed in parentheses. You can now bind objects in your project to the data.
Under Select the class to create an instance of, the following assemblies will be listed:
- Any CLR data sources that you have added as references in your project
To remove a data source
- Under Data in the Project
panel, select the data source that you want to
remove, and then click the Remove Data Source button,
or right-click the data source and then click Remove.
If there are any objects in your project whose properties were bound to the data in the data source that you removed, you will need to reset the properties before your project will build.