What Is XAML?
XAML (Extensible Application Markup Language) is a declarative, XML-based markup language created by Microsoft for defining user interfaces and object hierarchies in .NET applications. Instead of writing C# code that calls constructors and sets properties line by line, a developer writes XML elements that describe what the UI should look like, and a XAML parser translates that markup into an object graph at compile time or runtime. XAML powers UI frameworks including WPF, UWP, Xamarin.Forms, and .NET MAUI, and it is also used to describe non-visual resources such as styles, templates, and animations.
Cricket analogy: XAML is like a pre-submitted team sheet handed to the match referee before a Test at Lord's, declaring Rohit Sharma as opener and Bumrah as strike bowler, instead of shouting substitutions live over the boundary rope.
Why XAML Exists
XAML was designed to separate the declarative description of a UI from the imperative logic that drives it, letting designers work in tools like Blend while developers write C# or Visual Basic in the same project. Because XAML is just XML, it can be generated, parsed, and edited by tooling without executing any code, which is what enables the live visual designer and design-time preview in Visual Studio. This separation also makes UI structure easier to review, diff in source control, and restyle without touching application logic.
Cricket analogy: It's like how a curator prepares the pitch report (grass cover, expected turn) separately from the captain's bowling strategy, so groundstaff and coaches can each do their job without stepping on each other's decisions.
XAML as an Object Graph
Every XAML element corresponds to an instantiable .NET class, and every attribute corresponds to a property or event on that class. When the XAML parser reads a file, it walks the element tree, creates an instance for each element using its default constructor, converts attribute strings into the correct property types, and nests child objects according to the XML structure, ultimately producing the same object graph you would get by writing equivalent C# by hand.
Cricket analogy: It's like a scorecard being expanded into a full match report: each entry (batsman, runs, balls faced) maps directly to a database record, just as each XAML element maps to a constructed .NET object.
<Window x:Class="DemoApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Demo" Height="200" Width="300">
<Grid>
<Button Content="Click Me" Width="120" Height="32"
HorizontalAlignment="Center" VerticalAlignment="Center"
Click="OnButtonClick" />
</Grid>
</Window>XAML is entirely optional in most frameworks that support it — everything a XAML file produces (a Window with a Grid containing a Button) can also be written by hand in C# using constructors and property assignments. XAML is simply a more concise, tool-friendly, and designer-friendly way to express the same object graph.
Where XAML Is Used
XAML is not limited to a single framework: WPF and UWP use it for desktop and Windows Store apps, Xamarin.Forms and its successor .NET MAUI use a XAML dialect for cross-platform mobile and desktop UI, and Silverlight used an earlier variant for browser-based applications. Beyond top-level windows and pages, XAML is used pervasively for ResourceDictionaries, ControlTemplates, DataTemplates, and Storyboards, meaning a large share of the visual and behavioral definition of a modern .NET client application lives in .xaml files rather than in code.
Cricket analogy: It's like the toss protocol being used identically across formats — Tests, ODIs, and T20Is all start with a coin flip and a captain's call — even though the surrounding rules of each format differ.
- XAML is a declarative, XML-based markup language for building UI and object graphs in .NET applications.
- It separates UI structure (XAML) from imperative logic (C#/VB), enabling parallel designer and developer workflows.
- Every XAML element maps to a .NET class instance; every attribute maps to a property or event.
- The XAML parser converts markup into an object graph identical to hand-written equivalent code.
- XAML is used in WPF, UWP, Xamarin.Forms, and .NET MAUI, as well as in resource dictionaries and templates.
- Using XAML is optional — any XAML-defined UI could be constructed entirely in code instead.
Practice what you learned
1. What does XAML stand for?
2. Which of the following best describes XAML's relationship to hand-written C# UI code?
3. Which frameworks use a XAML dialect for defining UI?
4. What happens when the XAML parser reads an element like <Button Content="OK"/>?
5. Besides top-level windows and pages, what else is commonly defined in XAML?
Was this page helpful?
You May Also Like
XAML Syntax Basics
A practical walkthrough of core XAML syntax: object elements, property elements, content properties, and markup extensions.
XAML Namespaces
How xmlns declarations map XML prefixes to CLR namespaces and assemblies, enabling XAML to reference both framework and custom types.
Elements and Attributes in XAML
How XAML elements map to classes, attributes map to properties via type converters, and how attached properties and events fit into the same syntax.
XAML vs Code-Behind
How declarative XAML markup and imperative code-behind combine into one partial class, what belongs in each, and how MVVM shifts logic out of code-behind.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics
Microsoft TechnologiesMVVM Design Pattern Study Notes
.NET · 30 topics