The Load method is the managed API equivalent of the CreateFromXaml method in the JavaScript API. As with CreateFromXaml, the input to Load is a XAML fragment provided as a string, and the output is an object that can be added to the Silverlight object tree.
XamlReader in general is similar in design to "XmlReader" classes that are present in Silverlight (such as System.Xml..::.XmlReader or System.Xml..::.XmlDictionaryReader) as well as in other Microsoft development technologies. The XamlReader is a largely stateless static class with methods that create objects; it provides object construction behavior that parallels the XAML processing that generates run-time object trees from XAML in Silverlight.
There are several general concepts about creating objects from XAML that are identical whether you are using the JavaScript CreateFromXaml or the managed Load method:
-
The XAML content string must define a single root element.
-
The XAML content string must be well-formed XML, as well as being valid XAML.
There are also several notable differences between using XamlReader and using the CreateFromXaml method:
-
For XamlReader, the required root element must specify a default XML namespace. This is typically the Silverlight namespace, xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation". For CreateFromXaml, the namespace is implicitly assumed to be the default if not specified.
-
For Load, the newly created object tree should maintain a discrete XAML namescope when it is connected to the main Silverlight object tree. CreateFromXaml can also have this behavior if you specify an optional parameter, but the default behavior for object trees created from CreateFromXaml is that the XAML namescopes are merged if and when the object trees are combined. This introduces the possibility of name collisions at the time the merge is attempted.
-
JavaScript is loosely typed. The object returned from CreateFromXaml is within the JavaScript API and is interpreted implicitly in the context of the property it is being used to set. Explicitly casting the object return value is not necessary. By contrast, the managed API has the same strong typing requirements as managed code in general. Load returns a generic object. Before being added to the Silverlight object tree, the object must be of the type that is required by the property or collection where it is added, and this might require a cast.
[http://msdn.microsoft.com/en-us/library/cc189076%28VS.95%29.aspx]