XAML: The Markup Language for WPF and Workflow Foundation

XAML: The Markup Language for WPF and Workflow Foundation

XAML, which originally stood for Extensible Avalon Markup Language, is a powerful declarative language used by Microsoft to define user interfaces and logic. While it began as the backbone for "Avalon"—the internal code-name for Windows Presentation Foundation (WPF)—its utility expanded during the development of .NET Framework 3.0, leading Microsoft to adopt it for Workflow Foundation (WF) as well.

XAML in Windows Presentation Foundation (WPF)

In the context of WPF, XAML is primarily used to describe visual user interfaces. It provides a flexible way to define a wide array of visual elements, including 2D and 3D objects, rotations, and complex animations. This separation of the UI definition from the backend logic allows developers to create rich, interactive experiences more efficiently.

[ไม่มีภาพประกอบ]

The Compilation Process: From XAML to BAML

To optimize performance, XAML files are not always processed as raw text at runtime. Instead, a XAML file can be compiled into a Binary Application Markup Language (BAML) file. This BAML file is then inserted as a resource into a .NET Framework assembly. When the application runs, the framework engine extracts the BAML, parses it, and generates the corresponding WPF visual tree.

XAML in Workflow Foundation (WF)

Beyond visual interfaces, XAML is used within Workflow Foundation to describe declarative logic. This is particularly useful for long-running processes, such as those generated by rules systems or process modeling tools.

Historically, the serialization format for workflows was known as XOML to distinguish it from UI markup. While Microsoft no longer distinguishes between the two in terms of the language itself, the file extension .xoml is still used for files containing workflow markup.

Design and Styling

XAML manages the "look and feel" of an application through a system called Templates. Unlike the syntax found in Cascading Style Sheets (CSS), XAML templates are more closely aligned with XBL (XML Binding Language).

Developers have several options for creating and editing XAML files, including:

Key Facts

  • Original Name: Extensible Avalon Markup Language.
  • Primary Uses: Defining WPF user interfaces and WF declarative logic.
  • Binary Format: XAML is compiled into BAML for inclusion in .NET assemblies.
  • Workflow Extension: Workflow-specific files use the .xoml extension.
  • Styling Method: Uses Templates rather than CSS-style syntax.
XAML Usage Comparison
Feature Windows Presentation Foundation (WPF) Workflow Foundation (WF)
Primary Purpose Visual User Interfaces Declarative Logic
Key Capabilities 2D/3D objects, animations, rotations Long-running processes, rules systems
File Extension .xaml .xoml
Runtime Result Visual Tree Workflow

Frequently Asked Questions

What does XAML stand for?

XAML originally stood for Extensible Avalon Markup Language, where "Avalon" was the code-name for Windows Presentation Foundation.

What is the difference between XAML and BAML?

XAML is the human-readable markup language used for development, while BAML (Binary Application Markup Language) is the compiled binary version used by the .NET Framework at runtime for better performance.

Does XAML use CSS for styling?

No, XAML does not use CSS syntax. Instead, it uses a system called Templates, which is more similar to XBL.

Can XAML be used for things other than user interfaces?

Yes, in the context of Workflow Foundation (WF), XAML is used to define long-running declarative logic and process models.

Which tools are used to create XAML files?

Common tools include Microsoft Visual Studio, Microsoft Expression Blend, XAMLPad, and the hostable WF visual designer.