What is Silverlight XAML?

Source: Internet
Author: User

This article is part 2 of the Silverlight series of interconnected power. It is intended for beginners of Silverlight and focuses on the basic features of Silverlight XAML. If you are not clear about what Silverlight is, refer to what Silverlight is.

XAML is called the Extensible Application Markup Language. It reads as "zammel". In plain terms, it represents the Silverlight interface, just as HTML represents the webpage interface. Without a doubt, to use Silverlight, you must understand XAML. Obviously, XAML is more complex than HTML and is not difficult to learn. XAML is also a script language and requires a dedicated parser to explain and execute. Each version has a corresponding parser. The Parser of Silverlight 4 cannot parse Silverlight 3, however, Microsoft provides the Silverlight 3 XAML parser in the Silverlight 4 core library for compatibility. You can use vs2010, blend, xamlpad, or a text editor to write XAML. It is just a "appearance language" after all ".

Vs2010 automatically generates a short piece of XAML code every time, as shown below:

 
  
<UserControl x:Class="MySilverlight.Page"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >  <Grid Background="OldLace">  </Grid></UserControl>

 

This text is saved in the file suffixed with. XAML, which is actually the source code file of XAML. You can see the interface effect through vs2010 or blend, and the area with the background "oldlace" is displayed. What else does it mean? first look at usercontrol, which is the base class of. Net user controls, which is common in Asp.net. The usercontrol class encapsulates the most necessary requirements of the Silverlight program and contains the basic part of the UI initialization. Microsoft believes that functions should be divided into small modules, and interface effects should be reused. Encapsulating controls is the most suitable method. In this way, each page of Silverlight is actually derived from the usercontrol class. This is similar to masterpage.

X: class = "mysilverlight. page "indicates that the current XAML has post code, which is placed in. XAML. the CS file contains the definition of the class corresponding to the XAML. X: Class specifies the class of the current XAML page, for example:

namespace MySilverlight{    public partial class Page : UserControl    {        public Page()        {            InitializeComponent();        }    }}

Let's take a look at xmlns, which is represented as a namespace, xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation", which is the namespace of XAML and referenced to the Silverlight core assembly, such as system. windows, xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" is the namespace used by The XAML language element, typically mapped to X: prefix. Here, by the way, why do you need to use so many namespaces? You need to reference different types, controls, and tags on the interface, all of which must have a unique name without ambiguity, these elements have different origins, so they need to be referenced in different ways. The xmlns keyword is used in the root element of each page to comply with the XML 1.0 specification.

Think about how to reference a Custom button that needs to be used in XAML. First, you must reference the namespace separately, use xmlns, and then declare the referenced CLR namespace CLR-namespace. The Assembly name is www.foxitjob.com. The complete statement is as follows:

 

<UserControl x:Class="MySilverlight.Page"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   xmlns:h="clr-namespace:www.foxitjob.com">

 

 

    

This control can be used only after being referenced:

 
<Grid background = "oldlace"> 

Copyright Internet power, source: http://www.foxitjob.com/2010/06/275.html

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.