因为在学习MAUI,所以学习一下XAML。
一个新的 .NET MAUI 应用包含三个 XAML 文件及其关联的代码隐藏文件。
App.xaml和它的App.xaml.cs,AppShell.xaml和它的AppShell.xaml.cs,MainPage.xaml和MainPage.xaml.cs。(这些里面的内容都是会自动生成的)
接着开始重点,基本的XAML语法。
在XAML种,设置类的属性有两种方法。
第一种我称之为正常写法:
<Label Text="Hello, World!"
VerticalOptions="Center"
FontAttributes="Bold"
FontSize="18"
TextColor="Aqua" />
第二种是拉出写的写法:
<Label Text="Hello, World!"
VerticalOptions="Center"
FontAttributes="Bold"
FontSize="18">
<Label.TextColor>
Aqua
</Label.TextColor>
</Label>
以上两种写法的TextColor是等效的。其中Label 作为XML元素的.NET MAUI对象。第二种方法的Textcolor是一个.NET MAUI属性,表示为XML元素。
第二种写法也可以写成如下的形式:
<Label Text="Hello, World!"
VerticalOptions="Center">
<Label.FontAttributes>
Bold
</Label.FontAttributes>
<Label.FontSize>
Large
</Label.FontSize>
<Label.TextColor>
Aqua
</Label.TextColor>
</Label>
先这样