共用方式為


OnLoad

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Establishes the handler for the Loaded event that occurs when the Silverlight plug-in has loaded into the browser DOM.

<object ...>
  <param name="onload" value="scriptHandlerName" />
...
</object>

Arguments

sender

object

The Silverlight plug-in that invoked the event.

args

object

Always null.

source

object

Root element of XAML content that was loaded.

Managed Equivalent

None. This event is an event on the Silverlight plug-in as it participates in the hosting browser's DOM, and is therefore out of the scope of the managed API for Silverlight. There is a closely related event (Loaded) but for all possible objects in the Silverlight object tree the Loaded event will fire before OnLoad.

Remarks

The Loaded event occurs after the XAML content in the Silverlight plug-in has completely loaded. The Loaded event cannot have handlers attached after plug-in initialization, because a forced reload of a Silverlight plug-in does not preserve any state; all state information must be transmitted in the new CreateObject and CreateObjectEx calls that initiate the load.

NoteNote:

Generally, it is not advisable to attempt to make sizing decisions in the event handler of this event. This is because the actualHeight and actualWidth values of the Silverlight plug-in, as possibly determined by the interaction with the browser's hosting code, are not guaranteed to be set at the time the OnLoad event occurs. Instead, you should use the OnResize handler for a different event, which occurs whenever the ActualHeight or ActualWidth properties change, including when the plug-in first loads.

The Loaded event always occurs after any Loaded event for a UIElement-derived class. Specifically, it occurs after the Loaded event on the root Canvas, which, in turn, is guaranteed to occur after all possible child elements have also raised the Loaded event.

The read-only IsLoaded property, which is set just before the Loaded event occurs, indicates whether the Silverlight plug-in is loaded.

You can add handlers for the Silverlight.js version of onLoad (for example, when you use Silverlight.createObject). This event wraps an underlying event that is defined at the level of the plug-in object model. The Silverlight.js version is not documented here; see documentation for Silverlight.js specifically.

The syntax shown is the objectparam syntax in HTML, which is what is required to set the value. You can also get the value with the following script: value = silverlightObject.onLoad; . However, this only references the name of the handler and is seldom useful.

Applies To

Silverlight Plug-in

See Also

Reference