Share via


SourceString Property

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Specifies the XAML content to render.

HTML
You cannot use this property in HTML.
Scripting

xamlContent = wpfeObject.sourceString

wpfeObject.sourceString = xamlContent

Property Value

xamlContent

Loads a string containing XAML content into the WPF/E control. Unlike the SourceElement property, the SourceString property can only be set at run time using JavaScript.

This property is read/write. The default value is null.

Remarks

You can load XAML content after the WPF/E control has been created by using the SourceString property. The following HTML example shows how to define a WPF/E control, whose content is loaded after the control has been created:

HTML
<html>
<head>
  <title>Load XAML Using the SourceString Property</title>
  <script type="text/javascript" src="aghost.js"></script>
  <script type="text/javascript" src="eventhandlers.js"></script>
</head>
<!-- The onload event is fired after the entire contents of the page has loaded. -->
<body onload="javascript:onPageLoaded()">
<div id="controlHost">
  <script type="text/javascript">
    new agHost(
               "controlHost",      // DIV tag id.
               "myControl",        // Control id.
               "360",              // Width of rectangular region of the control in pixels.
               "60");              // Height of rectangular region of the control in pixels.
                                   // All other property values are set to their default values.
  </script>
</div>
</body>
</html>

In order for XAML content to be loaded after the WPF/E control has been created, it is necessary to define a JavaScript event handler, not a WPF/E event handler, to initiate the loading of XAML content. The following JavaScript example shows an event handler function that corresponds to the onload event defined in the BODY tag of the previous HTML example.

JavaScript
// Event handling function for the Onload event defined in BODY tag.
function onPageLoaded()
{
    // Retrieve a reference to the control.
    var control = document.getElementById("myControl");
    // Define the XAML content.
    control.sourceString = '<TextBlock xmlns="https://schemas.microsoft.com/client/2007" Text="Hello, world" />';
    // Reload the control to force the property change to take effect.
    control.reload();
}

Notice that the reload method is invoked on the WPF/E control after the SourceString property has been set. The effect of the reload method is to override any previous settings of the Source and SourceElement property values.

Order of Precedence in Loading XAML Content

You can load XAML content into a WPF/E control using three different properties: Source, SourceElement, and SourceString. The WPF/E control establishes an order of precedence for each property definition to determine what XAML content should be loaded. The SourceString property takes the highest precedence, followed by the Source property, and then the SourceElement property. For example, if the Source property is defined, then the SourceElement property value is ignored.

Applies To

WPF/E Control

See Also

Using a WPF/E Control, Source, SourceElement