Windows.UI.Xaml.Core.Direct Windows.UI.Xaml.Core.Direct Windows.UI.Xaml.Core.Direct Windows.UI.Xaml.Core.Direct Windows.UI.Xaml.Core.Direct Namespace

Provides XamlDirect APIs that allow middleware to access most of Xaml at a more primitive level, achieving better CPU and working set performance.


XamlDirect XamlDirect XamlDirect XamlDirect XamlDirect

Represents the base class for all XamlDirect APIs. All of the XamlDirect APIs are instance methods off of this class.

XamlDirect is an API for accessing Xaml at a more primitive level for better CPU and working set performance.


IXamlDirectObject IXamlDirectObject IXamlDirectObject IXamlDirectObject IXamlDirectObject

Represents the primary object type that participates in the XamlDirect set of APIs.


XamlEventIndex XamlEventIndex XamlEventIndex XamlEventIndex XamlEventIndex

Enum that lists all the supported events in XamlDirect.

XamlPropertyIndex XamlPropertyIndex XamlPropertyIndex XamlPropertyIndex XamlPropertyIndex

Enum that lists all the supported properties in XamlDirect.

XamlTypeIndex XamlTypeIndex XamlTypeIndex XamlTypeIndex XamlTypeIndex

Enum that lists all the supported types in XamlDirect.


This example demonstrates how to create objects, set properties, and interface with standard UIElements in 3 ways: using XAML markup, using regular XAML types in C# and the new way using XamlDirect APIs.

In this example, we create a Border element and a Rectangle element and set a few properties on each. Then we add them to the tree of UI elements.

  1. Using XAML markup:
<Grid x:Name="RootGrid">
    <Border BorderBrush="Black" BorderThickness="5">
        <Rectangle Height="100" Width="100" Fill="Red" />
  1. Using regular imperative code, with full XAML types:
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(5);

Rectangle rectangle = new Rectangle();
rectangle.Height = 100;
rectangle.Width = 100;
SolidColorBrush rectBrush = new SolidColorBrush(Colors.Red);
rectangle.Fill = rectBrush;

border.Child = rectangle;

  1. Using XamlDirect code:

The following code will have higher performance than using full XAML types since all operations like instantiation and setting of properties on various elements are accomplished through IXamlDirectObjects instead of the full XAML types.

IXamlDirectObject border = XamlDirect.CreateInstance(XamlTypeIndex.Border);
XamlDirect.SetThicknessProperty(border, XamlPropertyIndex.Border_BorderThickness, new Thickness(5));

IXamlDirectObject borderBrush = XamlDirect.CreateInstance(XamlTypeIndex.SolidColorBrush);
XamlDirect.SetColorProperty(borderBrush, XamlPropertyIndex.SolidColorBrush_Color, Colors.Black);
XamlDirect.SetXamlDirectObjectProperty(border, XamlPropertyIndex.Border_BorderBrush, borderBrush);

IXamlDirectObject rectangle = XamlDirect.CreateInstance(XamlTypeIndex.Rectangle);
XamlDirect.SetDoubleProperty(rectangle, XamlPropertyIndex.FrameworkElement_Width, 100);
XamlDirect.SetDoubleProperty(rectangle, XamlPropertyIndex.FrameworkElement_Height, 100);

IXamlDirectObject rectBrush = XamlDirect.CreateInstance(XamlTypeIndex.SolidColorBrush);
XamlDirect.SetColorProperty(rectBrush, XamlPropertyIndex.SolidColorBrush_Color, Colors.Red);
XamlDirect.SetXamlDirectObjectProperty(rectangle, XamlPropertyIndex.Shape_Fill, rectangleBrush);

XamlDirect.SetXamlDirectObjectProperty(border, XamlPropertyIndex.Border_Child, rectangle);

RootGrid.Children.Add((UIElement) XamlDirect.GetObject(border));


XamlDirect is purpose built for middleware that predominantly use imperative APIs to create UI instead of markup. With XamlDirect APIs, you can achieve performance parity with the XAML parser even when creating UI imperatively in code.

XamlDirect APIs can be used side-by-side with traditional APIs and take advantage of the pay for play performance improvements.

Not all Xaml APIs are available with XamlDirect. The XamlTypeIndex enum lists all supported types, the XamlPropertyIndex enum lists all supported properties, and the XamlEventIndex enum lists all supported events.

Supported functions

You can perform the following functions using XamlDirect APIs:

All objects returned by XamlDirect.CreateInstance are of type IXamlDirectObject. All other APIs, such as the Set*Property APIs, take an IXamlDirectObject as their first parameter.

To convert an IXamlDirectObject to its full APINDEX, for example a Button, use the XamlDirect.GetObject method. Similarly, you can use XamlDirect.GetXamlDirectObject to convert from a full Object/DependencyObject to its XamlDirect equivalent instance.

See also

  • T:Windows.UI.Xaml.Core.Direct.XamlDirect * T:Windows.UI.Xaml.Core.Direct.IXamlDirectObject * T:Windows.UI.Xaml.Core.Direct.XamlTypeIndex * T:Windows.UI.Xaml.Core.Direct.XamlPropertyIndex * T:Windows.UI.Xaml.Core.Direct.XamlEventIndex