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

TypeCategoryDescription
XamlReaderClassParses XAML markup into object trees.
XamlWriterClassSerializes object trees to XAML markup.
IXamlServiceProviderInterfaceProvides services to XAML type converters and markup extensions.
XamlTypeClassRepresents a XAML type and its metadata.
XamlPropertyClassEncapsulates a XAML property definition.
XamlMemberClassRepresents 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);

See Also