当前位置:网站首页>Maui introductory tutorial series (5.xaml and page introduction)
Maui introductory tutorial series (5.xaml and page introduction)
2022-07-04 04:49:00 【Dotnet cross platform】
Preface
As a Microsoft UI frame , except Winform outside , Most are created by XAML File way to write front-end pages , Although you can also pass C# Code to write your user interface , And Xamarin.Forms identical , stay MAUI Write on XAML Is declared in the same way , The underlying part is reconstructed, but most of it inherits the original pattern .
Compared with other XAML Declarative UI frame , Such as :WPF、UWP、UnoPlatform、Avalonia Their declaration methods are different .
XAML Introduce
stay MAUI in , Create a XAML page , It mainly consists of two parts : XAML file +CS file .
XAML
<ContentPage
x:Class="MauiApp5.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<!-- -->
</ContentPage>x:Class : representative XAML The file points to partial class , XAML be responsible for UI Design , CS Class is responsible for writing business logic .
xmlns : full name xamlnamespace, The representative declared that XAML Namespace
xmlns:x="..." : Aliased naming xml Space , The objects under this namespace can be accessed through aliases ( Accessible )
problem 1: What is the difference between a namespace with an alias and a namespace without an alias ?
First , For one XAML In terms of documents , Only one namespace without alias can exist , In this way, you can access the objects under the namespace without alias , By default , We can use various... Provided by the framework UI object , This is the default , We don't need to show that we can access these objects through aliases , For our customized namespace , Can be accessed by alias .
Access objects under the default namespace
<Grid>
<StackLayout>
<Button/>
<Label/>
<Image/>
</StackLayout>
</Grid>Declare an alias to access the object
<m:ContentPage
x:Class="MauiApp5.MainPage"
xmlns:m="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<m:Grid>
<m:StackLayout>
<m:Button/>
<m:Label/>
<m:Image/>
</m:StackLayout>
</m:Grid>
</m:ContentPage>problem 2: x:Class What are the requirements of some classes pointed to ?
CS partial Class and XAML It's the same class , Just responsible for different work .XAML Usually more concise and readable than equivalent code , and C# Code can handle complex conditional judgments 、 Logical processing . Make sure , This part of the class needs and XAML The base class of is the same .
CS
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}Page introduction
MAUI Frame built in 4 Page types , To meet different application scenarios , as follows :
ContentPage
Content page , Usually used to define the visual layout of a page 、 Nested display sub elements, etcFlyoutPage
It contains a floating control page of display items and a detailed information page , It encapsulates the functions for side navigation and operationNavigationPage
Provides pages for forward and backward navigation

TabbedPage
Provide tab switching pages , Common in mobile devices .
These page types , They are all directly or indirectly inherited from Page class , Each realizes some functions .
summary
This paper mainly introduces MAUI in XAML File class description and several page types provided , The following article will mainly introduce XAML Specific layout and methods in .
边栏推荐
- @Feignclient comments and parameters
- Developing mqtt access program under QT
- 6-4漏洞利用-SSH Banner信息获取
- First knowledge of batch processing
- 更优雅地远程操作服务器:Paramiko库的实践
- 郑州正清园文化传播有限公司:针对小企业的7种营销技巧
- Rhcsa 03 - Basic permissions for documents
- LeetCode136+128+152+148
- Redis: order collection Zset type data operation command
- 网络设备应急响应指南
猜你喜欢
随机推荐
红队视角下的防御体系突破之第二篇案例分析
[go] database framework Gorm
What is the difference between Western Digital Green disk, blue disk, black disk, red disk and purple disk
Kivy教程之 更改背景颜色(教程含源码)
What is context?
1. Mx6u-alpha development board (LED drive experiment in C language version)
Eig launched Grupo Cerro, a renewable energy platform in Chile
[cloud native] those lines of code that look awesome but have a very simple principle
[Yugong series] go teaching course 001 in July 2022 - Introduction to go language premise
浅谈JVM的那些事
B. All Distinct
Rhcsa 06 - suid, sgid, sticky bit (to be added)
戳气球和布尔运算问题(巨难)
1. Mx6u-alpha development board (simulating STM32 drive development experiment)
网络设备应急响应指南
Wobo Union ended its strategic evaluation and decided to retain Bozi's business with excellent performance
红队视角下的防御体系突破之第一篇介绍、阶段、方法
Rhcsa 01 - create partitions and file systems
Developing mqtt access program under QT
Architecture practice camp - graduation project of module 9 of phase 6









