Several key concepts of XAML

Source: Internet
Author: User
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.

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.