Bagikan melalui


Use an object data source to connect to a database

You can add data sources directly to your Blend for Visual Studio 2012 project.

In a team production environment, developers might provide common language runtime (CLR) data sources to designers so that the designers can bind to data in their Blend projects in any way that they choose. 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 a SQL database), and converts the data to an ObservableCollection so that Blend (or any application that uses Windows Presentation Foundation (WPF)) can bind to the data.

For an example of a class library that is written in C# and an Blend project that binds to the resulting data, see Try it: Display data from a sample SQL database.

To add a CLR object data source

  1. On the Project menu, click Add Reference (Alt+Shift+R).

    The Add Reference dialog box appears.

  2. Browse to the assembly (.dll) that implements a data source. Select the assembly, and then click Open.

    The .dll file is added to the Reference node in the Projects panel.

  3. In the Data panel, click Create data source 601d2ab6-5e4b-49ab-bb3c-064456dc8184, and then click Create Object Data Source.

    The Create Object Data Source dialog box appears. Under Select the class to create an instance of, the following assemblies will be listed:

    • Any data source assemblies that you have added as references in your project.

    • Default project assemblies.

    Tip

    If you also want to see the available system assemblies, you can select the Show All Assemblies check box. Typing 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 the assemblies again.

  4. In the Data source name field, either type a name for this data source or leave the name as the default (ObjectDataSource).

  5. Under Select the class to create an instance of, expand the name of your assembly, select the object, and then click OK.

    The Data panel is now populated with the live data dc8f65fe-8ab3-4a8e-8963-e97ab3e4423c that is parsed from the 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. For more information, see Bind an object to data.

See Also

Tasks

Use a live XML data source

Delete a data source

Try it: Display data from a sample SQL database