
Parses a well-formed XAML fragment and creates a corresponding Silverlight object tree, and returns the root of the object tree.
Assembly: System.Windows (in System.Windows.dll)
'Declaration Public Shared Function Load ( _ xaml As String _ ) As Object
'Usage Dim xaml As String Dim returnValue As Object returnValue = XamlReader.Load(xaml)
Parameters
- xaml
- Type: System.String
A string that contains a valid XAML fragment.
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="http://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.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Silverlight
Supported in: 4, 3Silverlight for Windows Phone
Supported in: Windows Phone OS 7.0DataContext="{Binding RelativeSource={RelativeSource Self}}"
Depending on how much binding is happening between the child controls in the markup being loaded, binding errors may occur before the control gets to the OnApplyTemplate call; this will cause OnApplyTemplate to never get called at all. It's difficult to reproduce consistently until you reach a sufficient number of inter-element bindings; if you have enough of them, it'll fail every time.
The solution was to remove the DataContext declaration from the markup and apply it in code at the end of the OnApplyTemplate call:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
[Get template children]
DataContext = this;
}

- 2/27/2010
- E.Z. Hart
