Basic Binding knowledge (organization) and basic binding knowledge

Source: Internet
Author: User

Basic Binding knowledge (organization) and basic binding knowledge

The essence of a program is the data addition algorithm,

Algorithm distribution a. Database B. Read and Write back data c. business logic d. Data presentation e. Interface and logic Interaction

AB is stable. c is closely related to customer requirements (Development core). d. e is responsible for UI and logic interaction.

WPF makes the presentation layer subordinate to the logic layer. The key is to reference the Data Binding and its supporting Dependency Property System and DataTemplate.

 

A Binding source is a data source. It is generally a logical layer object (background), ElementName (in Xaml). Data is exposed to the outside through attributes.

Source object:

1. specify a single object of the common CLR type as a Source:. NET Framework built-in object and user-defined object.

2. specify the common CLR collection type object as Source: including array, List <T>, ObservableCollection <T> and other collection types. generally, the ItemsSource attribute of the control is associated with a collection object using Binding. for example, "ItemSource = DefaultView;" (DefaultView is an object of the DataView type. DataView implements the IEnumerable interface, so you can directly assign values to the ItemSource attribute) or directly assign values to ItemSource.

The ItemTemplate attribute is of the DataTemplate type.

3. ADO. NET data objects. Including DataTable and DataView: a virtual view of a DataTable, mainly used to display data

4. use XmlDataProvider to specify XML data as source: XML as the standard data storage and transmission format. some WPF controls are cascading (such as TreeView and Menu). We can specify the XML data of the tree structure as the Binding associated with the source.

5. Dependency object: The dependency object can be used not only as the Binding target, but also as the Binding source. The dependency attribute can be used as the Binding Path.

6. the container's DataContext (default Binding behavior) sets Binding, and only sets Path without Source. The Binding will find the Source by itself. (it will be searched along the control tree layer by layer until the object with the specified Path attribute is found)

7. ElementName. Find the object through the object Name attribute.

8. RelativeSource attribute: when the space needs to focus on its own, its own container or a value inside its own element

9. ObjectDataProvider object: When data from the data source is exposed to the outside world by means.

10. Use the Data Object retrieved by using LINQ as the Binding source.

Target refers to the control object of the UI Layer.

The attribute that elements on the UI care about is the Path of Binding, that is, the object has multiple attributes, specifying the attributes that interest it. the indexer can also be used as a Path. when the attribute of a set element is still a set, it can be skewed along the way. p91 page when The Bingding source itself is data and does not require Path to specify. XAML can be written as "SetBinding (TextBlock. textProperty, new Binding (". ") {Source = xxx })"

Enable the data source class to implement the INotifyPropertyChanged interface in the System. ComponentModel namespace.

 

SetBinding (DependencyProperty, BindingBase)

Binding UpdateSourceTrigger attribute. Optional values: PropertyChanged, LostFocus, Explicit, Default

 

Data validation of Binding. ValidationRule class. ValidationRules is the attribute of binding.

Implementation. First, a ValidationRule class is derived. Override the Validata method. (Specifying the verification scope)

Create a Binding in the form Constructor

ValidatesOnTargetUpdatad = true in the ValidationRule class. When the target (UI-Layer Control) changes, the data source will be affected.

 

DataContext is a dependency attribute. Usage:

1. When multiple controls on the UI follow the same object with Binding.

2. When the source object cannot be directly accessed, the DataContext of the outermost container is equivalent to the data commanding heights. As long as the elements are put up, other elements can be seen.

Related Article

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.