Property Elements
A separate XML node is used to represent the property value of a WPF object, which can represent more complex objects.
For example
<Button background = "yellow"/>
You can use property elements to indicate
<Button>
<Button. Background> yellow </button. Background>
</Button>
Simple objects seem to be more complex, but if you want to represent more complex objects, such
<Button>
<Button. Background>
<Solidcolorbrush>
<Solidcolorbrush. Color>
<Color a = "255" R = "255" G = "255" B = "255"/>
</Solidcolorbrush. Color>
</Button. Background>
</Button>
In this case, it is difficult to express it without property elements.
Type converters
Why can the previous background be assigned a value using a simple string like "yellow" or a complex object like solidcolorbrush? Isn't the WPF engine doing a lot of special processing?
In fact, WPF provides many types of conversion classes (type converter), which can convert strings to specific data types. For example, the front background is the brush type. In this way, you can define common objects with character constants for ease of use. This method is scalable and does not require hard encoding.
Markup extensions
Like PHP, ASP, and other languages, special code tags, such as "<%>", must be used to implement mixed HTML and Code compiling ". Similarly, in XAML, "{}" is used. In curly brackets, it is a. Net class object. It only has a simple usage, that is, simple function calls, and does not have process control. It does not look as common code. For example
Content = "{binding Path = height, relativesource = {relativesource self }}"
In XAML, Markup extensions is mainly used for object reference and data binding.
You can imagine that without Markup extensions, it is also possible to simply use XML to represent the above functions. For example
<Button. content>
<Binding Path = "height">
<Binding. relativesource>
<Relativesource>
Self
...
We can see that XML is very redundant. Therefore, I want to use Markup extensions for simplicity. If you replace XML with JSON, you may not need Markup extensions.