The createFromXaml Method
This extremely useful method allows you to add new XAML to the current render tree of the control. It takes two parameters: the first is a string containing the XAML that you want to use, and the second is a namescope, which if used will create unique names for the tags in this string so that they do not conflict with existing element names within the XAML tree.
When using this method, please note that you can only add new XAML elements that have a single root nodeāso if you have a number of elements to add, please make sure that they are all contained within a single container <Canvas>.
Additionally, createFromXaml does not immediately add the new XAML to the render tree. What it does is create a node within the render tree and return a reference to that node. You can then place this node in the correct position of the XAML render tree to add the new content to your Silverlight application. Here's an example:
function handleLoad(control, userContext, rootElement) {
var xamlFragment = '<TextBlock Canvas.Top="60" Text="Using CreateFromXAML" />'; textBlock = control.content.createFromXaml(xamlFragment); rootElement.children.add(textBlock);
As you can see, the xamlFragment is a string containing a new piece of XAML. This is created and a reference to it returned to the textBlock var. This reference is then added to the tree by adding it to the children of the root element.
Post a comment