XAML (eXtensible Application Markup Language) 是一种基于 XML 的声明性语言,主要用于 WPF、UWP、Xamarin.Forms 和 MAUI 等框架中构建用户界面。
基本语法结构
1. 根元素和命名空间声明
<Page x:Class="MyNamespace.MyPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace">
<!-- 内容 -->
</Page>
2. 对象元素语法
<Button Content="点击我" />
3. 属性语法
<Button Content="点击我" Background="LightBlue" Width="100" Height="30" />
4. 属性元素语法
<Button Width="100" Height="30">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="icon.png" Width="16" Height="16"/>
<TextBlock Text="点击我" Margin="5,0,0,0"/>
</StackPanel>
</Button.Content>
</Button>
5. 集合语法
<StackPanel>
<StackPanel.Children>
<Button Content="按钮1"/>
<Button Content="按钮2"/>
<Button Content="按钮3"/>
</StackPanel.Children>
</StackPanel>
<!-- 简写形式 -->
<StackPanel>
<Button Content="按钮1"/>
<Button Content="按钮2"/>
<Button Content="按钮3"/>
</StackPanel>
6. 内容属性语法
<!-- Label 的 Content 是内容属性 -->
<Label>这是一个标签</Label>
<!-- 等同于 -->
<Label Content="这是一个标签"/>
7. 标记扩展
<

最低0.47元/天 解锁文章
2263

被折叠的 条评论
为什么被折叠?



