What is Data binding
The DataContext property in the control base class (FrameworkElement, FrameworkContentElement) in WPF technology implements the binding mechanism, which is also supported in XAML. When the DataContext of a control changes, the DataContext of its child controls also inherits the DataContext of the parent control (provided that the child control is not assigned another value). The properties of the child control get the data from the data source, which enables XAML to get the values in the data source through the binding tag. Refresh data updates in each of its child controls when the data source is updated to achieve Toruk macto called effects!
Binding binding Tag
The XAML processor supports the syntax of the binding mechanism, appearing in the {Binding propertyname=value} format. Where PropertyName is basically divided into "data source specified tags, read data source tags, additional option tags," value can use other tags to get special values. A binding expression can be used in combination with a data source tag, a read data source tag, an additional option tag, or a parent control that inherits the data source of the parent control and binds it.
Grammar
<TextBox Name="theTextBox" />
<TextBlock Text="{Binding ElementName=theTextBox, Path=Text}"/>
同于
<TextBox Name="theTextBox" />
<TextBlock>
<TextBlock.Text>
<Binding ElementName="theTextBox" Path="Text" />
</TextBlock.Text>
</TextBlock>
Data source specified tag
Source property: To make any type of object instance as a data source through other extension tags, you can use tag settings such as StaticResource. For example: "{Binding source={staticresource xkeyelement}, Xpath=//item}", Xkeyelement is an object of XmlDataProvider. Gets the data as a data source with all the item-labeled nodes in Xkeyelement.
ElementName property: Make any object in the current XAML document with a value of elementname (x:name) as the data source. For example: "{Binding elementname=listbox1, path=selecteditem}" means that the SelectedItem property of ListBox1 is the data source of the current control.
RelativeSource property: Relative to the data source, use RelativeSource to make the object associated with itself a data source. For example: "Relativesource={relativesource Self}", the reader notes that "the middle is relativesource{} is an extension tag, and the outside relativesource={} is the binding tag property". This instance code means to get itself as a data source.