XAML Syntax Guide
Basic Structure
XAML (eXtensible Application Markup Language) is an XML‑based language used to define UI elements for Windows apps. A typical XAML file starts with a root element that defines the namespace declarations:
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Click Me" Width="100" Height="30"/>
</Grid>
</Window>
Elements & Attributes
Each UI component is represented by an element. Attributes correspond to properties of the element.
<TextBlock Text="Hello, World!" FontSize="24" Foreground="Blue"/>
Nested elements create a hierarchy, allowing you to compose complex layouts.
Namespace Prefixes
The x: prefix provides access to XAML language features such as x:Name, x:Key, and type casting.
<Button x:Name="SubmitButton" Content="{x:Static local:Resources.Submit}"/>
Markup Extensions
Markup extensions simplify complex property values.
<Image Source="{Binding Path=ProfilePicture}" />
<Rectangle Fill="{StaticResource PrimaryBrush}" />
Comments
Use standard XML comments to document XAML.
<!-- This button triggers the Submit command -->
<Button Content="Submit"/>