---
title: "Introduction to XAML"  
description: "In this post, I’m explaining about XAML.  What is XAML?XAML, which stands for Extensible Application Markup language. It’s a simple language based on"  
author: "priyanka kushwaha"  
published: 2015-03-20  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/10848/introduction-to-xaml  
category: ".net"  
tags: ["wpf", "xaml"]  
reading_time: 3 minutes  

---

# Introduction to XAML

In this post, I’m explaining about XAML.

##### \
What is XAML?

##

XAML, which stands for Extensible Application [Markup language](https://www.mindstick.com/interview/234/what-is-markup-language). It’s a simple language based on XML to create and initialize the .NET object with the hierarchical relation. It was [originally invented](https://answers.mindstick.com/qa/52009/java-language-was-originally-invented-by) for WPF it can be used to create any kind of object trees.

XAML Elements are .NET Classes

Each element in a XAML document refers to a .NET class. This means that both “<Window>” and “<Grid>” are .NET Classes.

Example:

This document includes only two elements- top-level window element, which represents the entire window, and the Grid, in which you can place all you control. Although you could use any top-level element. WPF application rely on just a few:

- Window
- Page (which is similar to window but used for navigable application)
- Application (which defines application resources and startup setting)

##### XAML property-Element syntax

##

Properties are normally written inline as known from XML <Button Content=”OK”/>. But what if we want to put a more [complex object](https://www.mindstick.com/forum/158088/unable-to-bind-a-view-with-the-complex-object-in-knockout-js) as content like an image that has properties itself or maybe a whole grid panel? To do that we can use the property [element syntax](https://www.mindstick.com/forum/157868/what-is-the-virtual-element-syntax-in-knockoutjs-and-how-is-it-used). This allows us to extract the property as an own child element.

```
<button>         <button.Content>                  < image source=”Image/OK.jpg” width=”50” Height=”50”>         </button.Content></button>
```

##### Implicit type conversion

##

A very powerful construct of WPF is implicit type converters. They do their work silently in the background. When You declare a BorderBrush, the word “Blue” is only a string. The implicit BrushConverter makes a System.Windows.Media.Brushes.Blue out of it. The same regards to the border thickness that is being converted implicitly into a Thickness object. WPF includes a lot of type converters for built-in classes, but you can also write type converters for your own classes.

```
<Border BorderBrush=”Blue” BorderThickness=”0,10”></Border>
```

##### Markup Extensions

###

Marker extensions are dynamic placeholders for the attribute value in XAML. They resolve the value of a property at runtime. Markup extensions are surrounded by [curly braces](https://answers.mindstick.com/qa/31876/when-we-use-curly-braces-in-the-string-format-its-not-working-in-c-sharp) (Example: Background=”{StaticResourceNormalBackGroundBrush}”). WPF has some built-in markup extensions, but you can write your own, by deriving from markup extension. These are built-in markup extensions:

1. Binding:

To bind the [values of two](https://www.mindstick.com/forum/158951/how-to-swap-the-values-of-two-variables-without-using-a-temporary-variable-in-python) properties together.

2. StaticResource:

On time lookup of a resource entry.

3. DynamicResource

Auto updating lookup of a resource entry.

4. TemplateBinding

To bind a property of a control template to a dependency property of the control.

5. x:static

Resolve the value of a static property.

6. x:null

Return null

Example:

```
<Textbox x:Name=”textbox”><Label Content=”{Binding Text, ElementName=textbox}”>
```

##### Namespaces:

##

At the beginning of every XAML file you need to include two namespaces:

The first is [http://schemas.microsoft.com/winfx/2006/xaml/presentation](http://schemas.microsoft.com/winfx/2006/xaml/presentation). It is mapped to all WPF controls in System.Window.Controls.

The second is [http://schemas.microsoft.com/winfx/2006/xaml](http://schemas.microsoft.com/winfx/2006/xaml) it is mapped to System.Windows.Markup that defines the XAML keywords.

The mapping between an [XML namespace](https://www.mindstick.com/interview/1284/what-characters-are-allowed-in-an-xml-namespace-prefix) and a CLR namespace is done by the XmlnsDefinition attribute at the assembly level.\
\

```
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></Window>
```

##### Mixing XAML with procedural Code

##

XAML-based windows store apps are a mix of XAML and procedural code. This section covers the two ways that XAML and code can be mixed together. Dynamically loading and parsing XAML yourself or leveraging the built-in support in [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) projects.

---

Original Source: https://www.mindstick.com/blog/10848/introduction-to-xaml

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
