WPF Learning (1)-XAML, wpf learning xaml

Source: Internet
Author: User

WPF Learning (1)-XAML, wpf learning xaml

Windows, Grid, TextBox, And Button are all called elements.

In the xaml document, <> is used to define tags. tags can be used to describe the attributes of elements or elements, for example:
<Window>
<Window. Resources>
</Window. Resources>
</Window>
Window is an element and Resources is an attribute of Window.

TAG content can contain tags of other elements, such
<Window>
<Grid>
<Button/>
</Grid>
</Window>
Some elements can only contain one child element, and some can contain many child elements.

Each element can have attributes, such
<Window>
<Grid>
<Button Height = "30"/>
</Grid>
</Window>

You can also use Attribute tags to describe the attributes of an element.
<Window>
<Grid>
<Button>
<Button. Height> 40 </Button. Height>
</Button>
</Grid>
</Window>
Attribute labels are more hierarchical, but they are not necessary for use.

The attribute value can be a string or a tag extension to perform complex operations such as binding data.
<Window>
<Grid>
<TextBox Text = "{Binding ElementName = slider1, Path = Value, Mode = OneWay}"/>
<Slider Height = "19" Name = "slider1" Width = "139"/>
</Grid>
</Window>

This can be written as an attribute tag.
<TextBox. Text>
<Binding ElementName = "slider1" Path = "Value" Mode = "OneWay"/>
</TextBox. Text>
This method is not powerful in vs2010, and smart prompts are not in place ......

Attributes can be attributes of not only elements, but also other elements.
The usage of referencing other element attributes is called an additional attribute. The referenced element must specify the namespace prefix.
<Window>
<Grid>
<Button x: Name = "btn1" Grid. Row = "2"/>
</Grid>
</Window>

Grid. Row does not have a prefix? That's because there is a default namespace xmlns. When using the classes it contains, you do not need to specify the namespace prefix.

The namespace is defined in the attributes of the root element.
<Window xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
X: Class = "App1.Window3">

</Window>

Xmlns defines the default namespace. It points to all the control classes of WPF.
Xmlns: x defines another namespace. Here, x is called the namespace prefix.
X: Class is an additional attribute that specifies the cs Class name in the post code.

The usage of classes in the x namespace is messy. Just remember the name.
X: Name
X: Class
X: Subclass
X: Type
X: Null
X: Key
X: Array
X: Static
X: Shared

X: Code
X: XData

Xmal is a markup language, just like html. Similar to Jquery,. net provides two help classes: VisualTreeHelper and LogicalTreeHelper.

 

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.