Microsoft.Xaml Namespace
Namespace Summary
The Microsoft.Xaml namespace provides types that support XAML parsing,
serialization, and runtime services for Windows Presentation Foundation (WPF)
and other XAML‑based frameworks. It includes classes for handling XAML markup,
converting objects to and from XAML, and exposing attached properties used by
the XAML engine.
Key Types
| Type | Category | Description |
|---|---|---|
| XamlReader | Class | Parses XAML markup into object trees. |
| XamlWriter | Class | Serializes object trees to XAML markup. |
| IXamlServiceProvider | Interface | Provides services to XAML type converters and markup extensions. |
| XamlType | Class | Represents a XAML type and its metadata. |
| XamlProperty | Class | Encapsulates a XAML property definition. |
| XamlMember | Class | Represents a member (property, event) of a XAML type. |
Sample Code
// Load XAML from a string
string xaml = @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
Content='Click Me' Width='100'/>";
var button = (System.Windows.Controls.Button)System.Windows.Markup.XamlReader.Parse(xaml);
Console.WriteLine(button.Content); // Output: Click Me
// Serialize a UI element to XAML
var stackPanel = new System.Windows.Controls.StackPanel();
stackPanel.Children.Add(new System.Windows.Controls.TextBlock { Text = "Hello" });
string serialized = System.Windows.Markup.XamlWriter.Save(stackPanel);
Console.WriteLine(serialized);