Share via


OnLoad Event

Occurs when the Silverlight plug-in has loaded.

Scripting (Instantiation)
Silverlight.CreateObject(,,,,{onLoad:functionName})

-or-

Silverlight.CreateObjectEx({events:{onLoad:functionName}})
Scripting (Runtime)
Cannot be raised in scripting, and cannot attach handlers for this event after initialization.

Event Handler Parameters (for Silverlight.js function onLoad parameters)

sender

object

Identifies the Silverlight plug-in that invoked the event.

context

object

User-specified context object, can be used to distinguish which instance of a Silverlight plug-in raised the event.

source

object

Root element of XAML content that was loaded.

Remarks

The OnLoad event occurs after the XAML content in the Silverlight plug-in has completely loaded. The OnLoad event cannot have handlers attached after plug-in initialization.

Note    Generally, it is not advisable to attempt to make sizing decisions within the event handler of this event. This is because the actualHeight/actualWidth values of the Silverlight plug-in are not guaranteed to be set at the time the OnLoad event fires. Instead, you should use OnResize. OnResize fires whenever the ActualHeight or ActualWidth properties change including when the plug-in first loads.

The OnLoad event occurs after any Loaded event for a UIElement-derived class, such as Canvas, TextBlock, or Rectangle. The read-only IsLoaded property, which is set before the Onload event occurs, indicates whether the Silverlight plug-in is loaded.

The onLoad event that you can add handlers for within the Silverlight.js file (e.g. when using Silverlight.createObject), wraps an underlying onLoad event that is defined at the level of the plug-in object model. The plug-in exposed event uses a different event handler signature, passing only the sender. You generally do not deal with the plug-in version of the onLoad event. The signature shown in the Event Handler Parameters section is the Silverlight.js version, which is how you generally attach handlers for this event. The Silverlight.js version of onLoad event handling expands on the plug-in exposed onLoad event handling in the following ways:

  • If there are several plug-in instances hosted in an HTML page, there is potential for confusion in event handlers about which instance was loaded. The CreateObject/CreateObjectEx functions in Silverlight.js add an optional context parameter for initialization. Typically this is set to a unique string. That context value is passed back as an event handler parameter, making it much simpler to write handler logic that can detect which plug-in's onLoad event is being handled at that time.
  • Rather than the generic sender object, the Silverlight.js version of onLoad passes the actual Silverlight plug-in instance as the first event handler parameter value. This saves you a call to sender.GetHost(), and you can store the return value as a variable in script for easy access to the Silverlight plug-in instance.

See Using the OnLoad Event for more information.

Applies To

Silverlight Plug-in

See Also

Writing Event Handlers for the Silverlight Instantiation OnLoad Event
Instantiating a Silverlight Plug-in (Using CreateSilverlight.js and Silverlight.js)
IsLoaded
Loaded