Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Using XamlReader.Load

 by Dinesh Beniwal on Sep 08, 2009

Read XamlReader.Load.
Comments: 0 Views: 7660 Printable Version 

 

Using XamlReader.Load

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 client namespace, http://schemas.microsoft.com/client/2007. For CreateFromXAML, the default XML namespace is implicitly assumed to be http://schemas.microsoft.com/client/2007 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.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
Team Foundation Server Hosting
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Tech Lead
Joined: Nov 04, 2008
Education: Masters Degree
 More Blogs from this Blogger
Initializing Compound Values
Deferred Query Evaluation
Extension Methods
Lambda Expressions and Expression Trees
Getting Started with Standard Query Operators
.NET Language-Integrated Query
Window Resizing
The Layout System in Silverlight
The Silverlight Plug-in Position and Dimensions
Colors and Brushes for Text Foreground
View all »
 Latest Blogs
Initializing Compound Values
Deferred Query Evaluation
Extension Methods
Lambda Expressions and Expression Trees
Getting Started with Standard Query Operators
.NET Language-Integrated Query
Window Resizing
The Layout System in Silverlight
The Silverlight Plug-in Position and Dimensions
Colors and Brushes for Text Foreground
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.