XAML (eXtensible Application Markup Language) is an XML-based language developed by Microsoft for designing user interfaces in WPF, UWP, WinUI, and .NET MAUI.
Instead of creating controls programmatically in C#, you describe your UI using XAML in a readable, hierarchical format.
Example #
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="My First WPF App"
Height="300"
Width="500">
<Grid>
<Button Content="Click Me"
Width="120"
Height="40"/>
</Grid>
</Window>
This code creates:
- A window
- A Grid layout
- A Button inside the Grid
Without XAML, you would need many lines of C# code to create the same interface.
XML Rules #
When writing XAML, remember these XML rules:
Every element must be closed #
Correct
<Button></Button>
or
<Button />
Incorrect
<Button>
Tags are case-sensitive #
Correct
<Button />
Incorrect
<button />
Elements must be properly nested #
Correct
<Grid>
<StackPanel>
</StackPanel>
</Grid>
Incorrect
<Grid>
<StackPanel>
</Grid>
</StackPanel>
