Extensible Application Markup Language (XAML ) is a declarative XML-based language developed by Microsoft for initializing structured values and objects. It is available under Microsoft's Open Specification Promise.
XAML is used extensively in Windows Presentation Foundation (WPF), Silverlight, Workflow Foundation (WF), Windows UI Library (WinUI), Universal Windows Platform (UWP), and .NET Multi-platform App UI (.NET MAUI). In WPF and UWP, XAML is a user interface markup language to define UI elements, data binding, and events. In WF, however, XAML defines workflows.
XAML elements map directly to Common Language Runtime (CLR) object instances, while XAML attributes map to CLR properties and events on those objects.
Anything that is created or implemented in XAML can be expressed using a more traditional .NET language, such as C# or Visual Basic .NET. However, a key aspect of the technology is the reduced complexity needed for tools to process XAML, because it is based on XML.
Technology
XAML originally stood for Extensible Avalon Markup Language, Avalon being the code-name for Windows Presentation Foundation (WPF). Before the end .NET Framework 3.0 development, however, Microsoft adopted XAML for Workflow Foundation (WF).
In WPF, XAML describes visual user interfaces. WPF allows for the definition of both 2D and 3D objects, rotations, animations, and a variety of other effects and features. A XAML file can be compiled into a Binary Application Markup Language (BAML) file, which may be inserted as a resource into a .NET Framework assembly. At run-time, the framework engine extracts the BAML file from assembly resources, parses it, and creates a corresponding WPF visual tree or workflow.
In WF contexts, XAML describes potentially long-running declarative logic, such as those created by process modeling tools and rules systems. The serialization format for workflows was previously called XOML, to differentiate it from UI markup use of XAML, but now they are no longer distinguished. However, the file extension for files containing the workflow markup is still ".xoml".
XAML uses a specific way to define look and feel called Templates; differing from Cascading Style Sheet syntax, it is closer to XBL.
To create XAML files, one could use Microsoft Expression Blend, Microsoft Visual Studio, the hostable WF visual designer, or XAMLPad.
Example
This Windows Presentation Foundation example shows the text "Hello, world!" in the top-level XAML container called Canvas.
<Canvas xmlns="http://schemas.microsoft.com/client/2010" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <TextBlock>Hello, world!</TextBlock> </Canvas>
The schema (the part) may have to be changed to work on your computer. Using a schema that Microsoft recommends, the example can also be
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<TextBlock>Hello, world!</TextBlock>
</Canvas>
This can be integrated into a Web page if WPF is installed using XBAPs (XAML Browser Applications) that are compiled applications running in a sandboxed environment hosted within the browser. Another way is to use the Silverlight plugin. The code cannot be included directly in an HTML page; rather it must be loaded into the page via JavaScript. If .NET 3.0 or later is installed, loose XAML files can also be viewed on their own in a compatible Web browser (including Internet Explorer and Firefox) in conjunction with the .NET Framework 3.0, without the need for the Silverlight plugin. Loose XAML files are markup-only files limited to defining the visual content to be rendered. They are not compiled with an application.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XAML Example</title>
<script type="text/javascript" src="MySilverlight.js" />
<script type="text/javascript" src="Silver.js" />
</head>
<body>
<div id="MySilverlight" >
</div>
<script type="text/javascript">
createMySilverlight(); </script> </body> </html> The MySilverlight.js file must contain the code that loads the above XAML code (as an XML file) under the MySilverlight HTML element.
A crucial part of utilizing XAML to its full potential is making appropriate usage of binding, as well as being comfortable with creating your own custom user elements as required, for your specific needs. Binding can be done as follows: <TextBox x:Name="txtInput" /> <TextBlock Text={ Binding ElementName=txtInput,Path=Text} />