Content Index Search
 

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.

  1. Under Data in the Project panel, click the +XML button.
  2. 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.
  3. In the URL for XML data field, enter a URL for your XML data file, or click Browse to locate a local file.
    Note 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.
  4. You can optionally click the expander to enter additional information for your data source, such as an XPath definition. 
    Note 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.
  5. 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.

  1. In the Project menu, click Add Reference (ALT+SHIFT+R).
    The Add Reference dialog box opens.
  2. 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.
  3. Under Data in the Project panel, click the +CLR Object button.
    The Add CLR Object Data Source dialog box opens.
  4. In the Data Source Name field, enter a name for this data source or leave it as the default (CLRObjectDataSource).
  5. Under Select the class to create an instance of, expand the name of your assembly, select the CLR object, and then click OK.
    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.
    Note 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
    • PresentationCore
    • PresentationFramework
    If you also want to see the available system assemblies, you can select the Show System Assemblies check box. Entering a query in the Search box will filter the assemblies to those that contain the search query. Remember to clear the Search box if you want to see all of the assemblies again.

To remove a data source