Export (0) Print
Expand All

Add or remove a data source

This page applies to WPF and Silverlight 2

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.

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 Try it: Create an RSS news reader.

Cc295239.alert_note(en-us,Expression.10).gifNote:

Silverlight 2 does not support XML data sources.

To add an XML data source

  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.

    Cc295239.alert_note(en-us,Expression.10).gifNote:

    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 makes sure 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.

    Cc295239.alert_note(en-us,Expression.10).gifNote:

    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.

Cc295239.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

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 Try it: Create a CLR object data source.

To add 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.

  6. 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

    • Default project assemblies

    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.

Cc295239.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

  • 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.

    Cc295239.alert_caution(en-us,Expression.10).gifCaution:

    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.

Cc295239.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

Community Additions

ADD
Show:
© 2014 Microsoft