In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the XAML file structure and parsing XAML example analysis, the article introduces in great detail, has a certain reference value, interested friends must read it!
XAML file structure
After we create the XAML file, we will see a structure similar to that shown in figure 1.16
Figure 1.16 structure
Among them, .xaml file and .xaml.cs file are the structure of XAML file. The following is an introduction to these two documents.
The .xaml file contains the XAML code, which is actually the XML syntax. Officially: it is a language for declaring objects, providing us with a convenient way to create objects. Similar to HTML, it is used to describe the content of the user interface (UI).
The .xaml.cs file associated with the .xaml file is usually called a code-behind file. If the developer references any of the events in .xaml (such as the Click event of Button), the corresponding event handling code will be written in this file.
Parsing XAML
After we create the XAML file above, we will see code similar to the following three.
(1) the first is to use Visual Studio to create the XAML code displayed in the XAML file after creating the project:
(2) the second is to use Xamarin Studio to create the XAML code displayed in the XAML file after creating the project:
(3) the third is to create the code displayed in the XAML file while creating the project:
The common parts of the three file codes are as follows:
The following is an explanation of the default part of the XAML public.
The first line is a simple description of XML, which contains the XML version number and the encoding format.
The function of the second line of code to the last line of code is what is needed to build the interface. Where the second and third lines refer to URL using two XML namespace (xmlns) declarations. Developers don't need to know what these URL points to. They are just URL owned by Xamarin and Microsoft, which basically act as version identifiers. The first XML namespace declaration means that an unprefixed tag is defined in the XAML file, which references classes in Xamarin.Forms, such as ContentPage. The second namespace declaration defines the prefix of x, which is used for several elements and attributes inherent in XAML itself and is (in theory) supported by all implementations of XAML.
Note: these elements and attributes vary slightly depending on the year embedded in the URL. Xamarin.Forms supports the 2009 XAML specification, but not all.
Fourth line of code. Immediately after the x prefix is declared, it is used for an attribute named Class, because the use of this x prefix is very common in XAML files. For example, Class is called x:Class for short. X:Class specifies the .NET class name.
Note: the x:Class attribute can only appear in the root element of the XAML file to define a derived C # class.
For the definition of the x:Class specified class, the developer can see it in the .xaml.cs file, and the code is similar to the following code:
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Text
Using System.Threading.Tasks
Using Xamarin.Forms
Namespace Hello
{
Public partial class MainPage: ContentPage
{
Public MainPage ()
{
InitializeComponent ()
}
}
}
Note: the type indicated by the value of x:Class must be declared using the partial keyword. This merges the classes parsed by XAML with the parts defined in the .xaml.cs file. Because of this partial mechanism, we can leave the logic code of the class in the .xaml.cs file and implement it in the C # language, and separate the code related to the declaration and layout UI elements to achieve the logical separation of UI.
The above is all the contents of the article "sample Analysis of XAML File structure and parsing XAML". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.