Windows Phone One, XAML base syntax

Source: Internet
Author: User
Tags closing tag opening and closing tags silverlight

Namespace for XAML

namespace Format : syntax structure is "xmlns:" + "namespace prefix name", default namespace does not need to define namespace prefix name "xmlns"

Declaration of the namespace

<page

X:class= "App1.mainpage"

Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"

Xmlns:local= "Using:app1"

Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"

Xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"

Mc:ignorable= "D"

Background= "{ThemeResource Applicationpagebackgroundthemebrush}" >

Use of namespaces: Constrains the document specification to clarify the type of label.

xmlns (XML Namespace) default namespace

Xmlns:x can be understood to alias namespaces

xmlns is not specific or specifically defined in XAML, it is XML, and is intended to constrain the document structure of XML

Xmlns:d and Xmlsn:ms are designed for Visual Studio view services without any impact to the program

URI Uniform Resource Locator: "Http://schemas.microsoft.com/winfx/2006/xaml"

XAML name Range (x:) language attribute

x:class

Configure XAML compilation to connect partial classes between markup and code-behind. The code partial class is defined in a separate code file, and the markup partial class is created by the code by the XAML during compilation.

<object

x:class= "Namespace.ClassName" ...>

...

</object>

x:FieldModifier

Modifies the XAML compilation behavior so that the field referenced by the specified object is defined with public access instead of the default private behavior.

<object

x:fieldmodifier= "Public"

.../>

x:key

Uniquely identifies the elements that are created and referenced as resources that exist in a resourcedictionary.

<ResourceDictionary>

<object x:key= "Stringkeyvalue" .../>

</ResourceDictionary>

Used in implicit ResourceDictionary:

<object. Resources>

<object x:key= "Stringkeyvalue" .../>

</object. Resources>

x:name

Uniquely identifies an object element, which makes it easy to access an instantiated object from code-behind or generic code. After being applied to a supported programming model, x:name can be considered equivalent to a variable that holds an object reference (returned by a constructor).

X:key and x:name are not the same concepts.

X:key is used only in resource dictionaries.

X:name is used for all areas of XAML.

A findname call that uses a key value does not retrieve the key resource.

X:uid

Provides a unique identifier for the markup element. For Windows runtime XAML, this unique identifier is used by the XAML localization process and tools.

<button

X:uid= "ResourceKey"

Content= "is replaced by the value in the resource key to" Resourcekey.content "/>

It is often used when developing a multi-lingual system.

Other XAML intrinsic data types are declarations of common simple data types:

X:boolean

For CLR support, the primitive corresponds to a Boolean. XAML parses the value of X:boolean in case-sensitive. Please note that "X:bool" is not an acceptable alternative primitive.

X:string

For CLR support, the primitive corresponds to the String。 Encoding the string by default takes the enclosing XML encoding. x:double

For CLR support, the primitive corresponds to a Double. In addition to numeric values, thex:double text syntax supports the token "NaN", which is how the "Auto" of the layout behavior is stored as a resource value. The processing of these tokens is case-sensitive. You can use the scientific notation, for example, to write 1,000,000 as "1+e06".

X:int32

For CLR support, primitives correspond to Int32. X:int32 are considered to be signed, you can include a minus sign ("-") for a negative integer. In XAML, missing symbols in text syntax represent signed positive values.

How objects are declared

Instantiate an object as a XAML-formatted element using the opening and closing tags

<Canvas>

</Canvas>

Objects can contain other objects

<Canvas>

<Rectangle></Rectangle>

</Canvas>

If an object contains no other objects, you can use a self-closing tag to declare the object

<Rectangle/>

XAML Create object element

    • The label name is the control name
    • A XAML file allows only one root object element page
    • Label properties or sub-labels are manipulated for control object properties
    • Each XAML tag will have a corresponding type
    • Each declaration of a XAML node is equivalent to creating an object of the appropriate type
    • which element node to add the tag to is the equivalent of the object under which to add the object.

Property settings Four Ways

? property Key-value Syntax

? attribute element Syntax

? content element Syntax

? Implicit collection Syntax

Different property types We can choose different setting methods

Simple type data, such as strings, numbers, and the like using key-value forms, i.e. propname= "PropValue"
Complex type data, such as text block values, button contents, background images, using attribute element forms
Content element Syntax (default syntax) for convenience
Set properties Use Set syntax

Property key-Value syntax:

Only instantiated objects can set instance properties, in the following format:

<objectname propertyname= "PropertyValue"/>

Or

<objectname propertyname= "PropertyValue" >

<objectName>

Each property corresponds to a property value, and the property value type must match the property

Multiple properties of an object can be set in a tag

ObjectName is the object to instantiate, PropertyName is the property name that needs to be set, PropertyValue is the value of the property

<canvas width= "height=" background= "Red"/>

Or

<canvas width= "height=" background= "Red" >

</Canvas>

Most properties are manipulated in the form of attribute key values

Requires that the attribute type must be a "simple/convertible" type

Built-in property type converters

Control properties for some complex types only

Used to convert a string set in a XAML property into the appropriate strongly typed data

For example:

<button

X:name= "BTN"

Horizontalalignment= "left"/>

Contrast

Btn. HorizontalAlignment = HorizontalAlignment.Left;

You only need to set the HorizontalAlignment property to the left string in XAML to change the control's horizontal property to align its properties

attribute element Syntax

Some properties can be set using property element syntax in the following format:

<object>

<object.property>

<!-element attribute value--

</object.property>

</object>

If the property of an object is a complex type and cannot be represented directly by a simple string, then the syntax of the property element needs to be used:

< tag name >

< tag name. property name >

< attribute value/>

</tag name. property name >

</Tag name >

Text block value, button content, background picture

<ellipse width= "height=" >

<Ellipse.Fill>

<solidcolorbrush color= "Green"/>

</Ellipse.Fill>

</Ellipse>

Content element syntax

Attributes of some elements support content element syntax, allowing the names of elements to be ignored

Instance objects set properties based on the first tag value in a XAML element

Use content element syntax more flexibly for large amounts of formatted text

A large amount of textual content can be inserted between attribute tags

<textblock>windows 10</textblock>

There is a default property for most object elements;

Set the element's "InnerText" directly to the property value:

For example:

<button x:name= "btn1" content= "Hello"/>

<button x:name= "BTN2" >

World

</Button>

Default properties are known through attribute tags

[Contentproperty (Name = "Content")]

Implicit collection syntax

Element supports a collection of attribute elements to set properties using the collection syntax

Use the Add method of managed code to add more collection elements

The essence is to add property items to the collection of objects

Prior to this we considered the properties of the non-aggregate nature;

For a property of a collection class, the set value can be implemented in the same way as a repeating child element:

<Grid>

<Grid.Children>

<TextBlock>Hello1</TextBlock>

<TextBlock>Hello2</TextBlock>

<TextBlock>Hello3</TextBlock>

<TextBlock>Hello4</TextBlock>

<TextBlock>Hello5</TextBlock>

</Grid.Children>

</Grid>

<rectangle width= "height=" >

<Rectangle.Fill>

<LinearGradientBrush>

<GradientStopCollection>

<gradientstop offset= "0.0" color= "Gold"/>

<gradientstop offset= "1.0" color= "Green"/>

</GradientStopCollection>

</LinearGradientBrush>

</Rectangle.Fill>

</Rectangle>

<rectangle width= "height=" >

<Rectangle.Fill>

<LinearGradientBrush>

<LinearGradientBrush.GradientStops>

<gradientstop offset= "0.0" color= "Gold"/>

<gradientstop offset= "1.0" color= "Green"/>

</LinearGradientBrush.GradientStops>

</LinearGradientBrush>

</Rectangle.Fill>

</Rectangle>

An implicit property setting method for omitting GradientStopCollection

attached Properties

Attaching properties to elements that support attached properties

Attached properties are created by the parent element that supports the attached property, and the element that supports the attached property inherits the property of the parent element in which it resides

Format of attached property: Attachedpropertyprovider.propertyname

Attachedpropertyprovider is the provider of the attached property, PropertyName is the name of the attached property

<Canvas>

<rectangle canvas.left= "" "canvas.top=" "width=" "height=" "Ten" radiusx= "radiusy=", fill= "Gold"/>

</Canvas>

The rectangle element sets the Canvas.Left and Canvas.Top properties, which are included in the <Canvas>...</Canvas> when using Canvas for layout The elements between will produce additional properties relative to the canvas object Canvas.Left and Canvas.Top properties

dependency property

English Name: Dependency Properties

Dependency properties are similar to CLR properties, providing an access wrapper for an instance-level private field that implements read-write operations for properties through GetValue and SetValue accessors

One of the most important features is that property values depend on one or more data sources, and the way they are provided can be different

Because it relies on multiple data sources, it is called a dependency property.

XAML the routed event (Routed Events processing methods can be divided into three kinds:

bubbling event, the Bubbling event, which is the most common way of handling events. This event indicates that after an object activates an event, it propagates along the object tree from bottom to top, child to parent, until it is processed or arrives at the corresponding root object element, or the event is routedeventargs.handled=true when it is due. In propagation, all the element objects involved can be controlled by the event. This event can be supported by Windows 8,silverlight.

Tunneling Event (tunneling event), which, in contrast to bubbling events, propagates from the root object element to the child object of the activation event after the object activates the event.

Or when the event is due to routedeventargs.handled=true, complete the processing. This event is supported only for Windows 8.

A direct routed event (directly Routing event)that does not propagate up or down, only on the object that is currently active for the event. This event can be supported by Windows 8,silverlight.

Common markup Extensions

Binding Markup Extension

{Binding} provides a value for the Data-bound property that can be deferred to the runtime. The binding markup extension is converted to an intermediate expression object when the XAML is loaded. The data-binding engine uses expressions and data contexts at run time to determine property values.

Customresource Markup Extension

Provides a value for any XAML property by calculating a reference to a resource that originates from a custom resource lookup implementation. Resource lookups are performed through the Customxamlresourceloader class implementation.

RelativeSource Markup Extension

Provides a way to specify a binding source as a relative relationship in the run-time object graph.

StaticResource Markup Extension

Provides a value for any XAML property by calculating a reference to a defined resource. A resource is defined in a ResourceDictionary , a staticresource usage that references the key of the resource in ResourceDictionary.

TemplateBinding Markup Extension

Links a property value in one control template to the value of one of the other exposed properties on the template control. TemplateBinding can only be used in one ControlTemplate definition in XAML.

ThemeResource Markup Extension

Uses the additional system logic to retrieve different resources based on the currently active topic, by calculating the referral to a resource to provide a value for any XAML attribute. Similar to StaticResource , a resource is defined in ResourceDictionary and Themeresource usage refers to the key of the resource in ResourceDictionary.

Windows Phone One, XAML base syntax

Related Article

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.