NET MAUI class (such as ContentPage or Label) appears in the XAML file as an XML element. The following example shows a ContentPage containing a Label: įrom the example above the relationship between classes, properties, and XML should be evident. The child of the ContentPage is automatically set as the value of the ContentPage.Content property. Set page contentĪ ContentPage should contain a single child, that can be a view or a layout with child views. However, Shell is beyond the scope of this introduction to XAML. NET MAUI Shell to set the first page of the app to be displayed. The MainPage constructor calls InitializeComponent, which initializes all the objects defined in the XAML file, connects them all together in parent-child relationships, attaches event handlers defined in code to events set in the XAML file, and sets the resultant tree of objects as the content of the page. The AppShell class instantiates the first page of the app to be displayed, which is MainPage. When Visual Studio builds the project, a source generator generates new C# source that contains the definition of the InitializeComponent method that's called from the MainPage constructor and adds it to the compilation object.Īt runtime, code in the MauiProgram class bootstraps the app and executes the App class constructor, which instantiates AppShell. The MainPage class derives from ContentPage, and is a partial class definition. Public partial class MainPage : ContentPage The file looks similar to this: namespace MyMauiApp Everything else that appears in a XAML file is instead simply instantiated from existing classes and initialized. This is the only new class defined in the XAML file. The x:Class attribute can only appear in the root element of a XAML file to define a derived C# class. This means that this XAML file defines a new class named MainPage in the MyMauiApp namespace that derives from ContentPage (the tag in which the x:Class attribute appears). NET class name: the MainPage class in the MyMauiApp namespace. The x:Class attribute specifies a fully qualified. Because the use of this x prefix is virtually universal for the XAML namespace, XAML attributes such as Class are almost always referred to as x:Class. However, these elements and attributes are slightly different depending on the year embedded in the URI.NET MAUI supports the 2009 XAML specification.Īt the end of the first tag, the x prefix is used for an attribute named Class. This is used for several elements and attributes that are intrinsic to XAML itself and which are supported by other implementations of XAML. The second namespace declaration defines a prefix of x. The first XML namespace declaration means that tags defined within the XAML file with no prefix refer to classes in. However, there's no content at these URIs, and they basically function as version identifiers. The two XML namespace ( xmlns) declarations refer to URIs on. The MainPage.xaml file has the following structure: This is true of the MainPage.xaml and files. Most other classes with XAML files contribute to a class that derives from ContentPage, and define the UI of a page. The second file pairing is AppShell.xaml and, which contribute to a class named AppShell that derives from Shell. Both App.xaml and contribute to a class named App that derives from Application. The first file pairing is App.xaml, a XAML file, and, a C# code-behind file associated with the XAML file. NET MAUI app contains three XAML files, and their associated code-behind files: Within the XAML file, classes and properties are referenced with XML elements and attributes, and links between the markup and code are established. Together, these two files contribute to a new class definition that includes child views and property initialization. The code-behind file provides code support for the markup. NET Multi-platform App UI (.NET MAUI) app, XAML is mostly used to define the visual contents of a page and works together with a C# code-behind file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |