WPF and Silverlight Learning notes (24): Data source provider (Dataprovider)

Source: Internet
Author: User
Tags silverlight

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:}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.