WPF Learning (i)-XAML

Source: Internet
Author: User

Window, Grid, TextBox, button, etc., are called elements.

In a XAML document,,<> is used to define a label, which can be used to describe the attributes of an element or element, such as:
<Window>
<Window.Resources>
</Window.Resources>
</Window>
Window is an element, and resources is a property of window

The label content can contain labels for other elements, such as
<Window>
<Grid>
<button/>
</Grid>
</Window>
Some elements can contain only one child element, and some can contain many child elements.

Each element can have attributes, such as
<Window>
<Grid>
<button Height = "/>"
</Grid>
</Window>

The attributes of the description element can also be written in the form of property labels
<Window>
<Grid>
<Button>
<button.height>40</button.height>
</Button>
</Grid>
</Window>
Attribute tags are more hierarchical, but super verbose, no need to use

The value of a property can be a string, or a complex operation like binding data can be done in the form of markup extensions.
<Window>
<Grid>
<textbox Text = "{Binding elementname= slider1, Path=value, mode=oneway}"/>
<slider height= "name=" Slider1 "width=" 139 "/>"
</Grid>
</Window>

Using the attribute tag, you can write this
<TextBox.Text>
    <binding elementname = "Slider1" Path = "Value" mode= "OneWay"/>
</TextBox.Text>
This type of writing in the vs2010 is not to force, smart tips are not in place ...

Property can be not only the element itself, but also the properties of other elements
The use of referencing other element properties is called an attached property, and the referenced element must specify the namespace prefix
<Window>
<Grid>
<button x:name = "Btn1" grid.row = "2"/>
</Grid>
</Window>

Grid.Row no prefix? That's because there's a default namespace, xmlns, that uses the classes it contains without having to specify the namespace prefix

Namespaces are defined in the properties 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>

The xmlns definition is the default namespace, which points to all of WPF's control classes.
Xmlns:x defines another namespace, where x is called a namespace prefix and can be understood as a short name.
X:class is an attached property that indicates the CS class name in the post code

Classes under the X-namespace use a mess, 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 jquery,.net also offers two helper classes: VisualTreeHelper, Logicaltreehelper

WPF Learning (i)-XAML

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.