In WPF, the system provides two data source providers (Dataprovider): An Object data source provider (ObjectDataProvider) and an XML data source provider (XmlDataProvider). It acts like an object data source (ObjectDataSource) and an XML data source (XmlDataSource) in an asp.net data source (DataSource). Its inheritance structure is as follows:
ObjectDataProvider is used to process data sources generated by the return value of a method, and is widely used, and often multi-tier applications use ObjectDataProvider to process data generated by the component layer on the interface. In this section we mainly deal with ObjectDataProvider, and for XmlDataProvider interested friends can refer to MSDN.
One, component-side definition
For example, define a class library project in which you define a ProductInfo class, a CategoryInfo class, to encapsulate the Products table in the Northwind database and the data in the Categories table. Defines NorthwindDataSet, containing product, category two DataTable. Defines the DataControl class, handles operations on the Northwind database, and returns the appropriate encapsulated type or collection as the data source for the interface display.
1, ProductInfo class and CategoryInfo class
1:namespace wpf_24_library
2: {
3:///<summary>
4:///Packaging Product table information
5:///</summary>
6:public class ProductInfo
7: {
8:public int ProductID
9: {
10:set; Get
11:}
12:public string ProductName
13: {
14:set; Get
15:}
16:public decimal UnitPrice
17: {
18:set; Get
19:}
20:public int CategoryID
21: {
22:set; Get
23:}
24:}
25:}
1:using System.Collections.Generic;
2:
3:namespace wpf_24_library
4: {
5:///<summary>
6: Information on the///Package category table
7:///</summary>
8:public class CategoryInfo
9: {
10:public CategoryInfo ()
11: {
12:products = new list<productinfo> ();
13:}
14:
15:public int CategoryID
16: {
17:set; Get
18:}
19:public string CategoryName
20: {
21:set; Get
22:}
23:
:///<summary>
25:///encapsulates all products of this category
:///</summary>
27:public list<productinfo> Products
28: {
29:private set; Get
30:}
31:}
32:}