Occurs when the Silverlight content is loaded into the host Silverlight plug-in and parsed, but before the content is rendered.
| XAML | <object Loaded="eventhandlerFunction" .../> |
| Scripting |
[token = ]object.AddEventListener("Loaded", eventhandlerFunction)
|
AddEventListener Parameters
| token | integer A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token. |
| eventhandlerFunction | object The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotes around the function name are not required. See Remarks. |
Event Handler Parameters
| sender | object Identifies the object that invoked the event. |
| eventArgs | object This parameter is always set to null. |
Examples
The following XAML example shows Loaded events defined for a Canvas and TextBlock object. In this case, the TextBlock object's event handler function is invoked before the Canvas object's event handler function.
| XAML |
<!-- TextBlock Loaded event fires first, then Canvas Loaded event -->
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="rootCanvasLoaded">
<TextBlock
x:Name="myTextBlock"
Loaded="textBlockLoaded"
Text="Test order of Loaded events" />
</Canvas>
|
The following JavaScript example shows how to implement a Loaded event handler function. Notice that the eventArgs parameter is omitted, since it is not referenced by the function:
| JavaScript |
function rootCanvasLoaded(sender)
{
// Set the TextBlock to display the current date and time.
sender.findName("myTextBlock").text = Date();
}
|
The Silverlight plug-in provides an OnLoad event that occurs after the XAML content in the Silverlight plug-in has completely loaded. This means that the Onload event always occurs after any Loaded events occur.
JavaScript provides a set of events that you can use to respond to changes in the Web page, including the onload event. You can use the onload event and the Silverlight Loaded event on the same page. The following HTML example shows how to use the onload event:
| JavaScript |
<body onload='javascript:alert("onload event generated")'>
|
In this example, JavaScript code is used directly instead of referencing an event handler function--this is not possible with Silverlight events. By definition, the JavaScript onload event is not fired until the entire Web page is loaded. This means that any Silverlight plug-in contained within the page will fire its Loaded event before the JavaScript onload event.
Applies To
Canvas,
Ellipse,
Glyphs,
Image,
InkPresenter,
Line,
MediaElement,
Path,
Polygon,
Polyline,
Rectangle,
TextBlock
See Also
Silverlight Events
OnLoad