XamlReader.Load Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Parses a well-formed XAML fragment and creates a corresponding Silverlight object tree, and returns the root of the object tree.

Namespace:  System.Windows.Markup
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Shared Function Load ( _
    xaml As String _
) As Object
public static Object Load(
    string xaml
)

Parameters

  • xaml
    Type: System.String
    A string that contains a valid XAML fragment.

Return Value

Type: System.Object
The root object of the Silverlight object tree.

Remarks

Usage for Load is documented thoroughly in the topic Using XamlReader.Load.

A "well-formed XAML fragment" must meet the following requirements:

  • The XAML content string must define a single root element.

  • The content string XAML must be well formed XML, as well as being parseable XAML.

  • The required root element must also specify a default XML namespace value. This is typically the Silverlight namespace, xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation". This XML namespace is required explicitly in Silverlight 2 and onward whereas it was implicitly assumed in Silverlight 1.0 and its CreateFromXaml JavaScript method.

Note that these conditions report parsing exceptions but the message in the exception will specifically note the cause indicating a general format failure rather than a specific parsing failure against the vocabulary identified by the XML namespace.

Beyond being "well-formed", Load will also report failures that occur when the XAML is submitted to the parser. See "XAMLReader.Load and Parsing Behavior" section of Using XamlReader.Load.

Any objects with a Name or x:Name value in the input XAML will be considered to be within a discrete XAML namescope, once the returned object tree is added to the main object tree. This can influence your ability to find the object in scope with FindName. For details, see "XAML Namescope Considerations" section of Using XamlReader.Load.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.