OnResize Event

Occurs whenever the ActualHeight or ActualWidth property of the Silverlight plug-in changes.

Scripting (Instantiation)
Cannot add handlers during instantiation
Scripting (Runtime)
silverlightObject.onResize = functionName

Event Handler Parameters

sender

object

Identifies the object that invoked the event (the Silverlight plug-in).

eventArgs

object

This parameter is always set to null.

Remarks

The OnResize event occurs whenever the Silverlight plug-in changes its ActualHeight or ActualWidth property when in embedded mode. When the Silverlight plug-in is in full-screen mode, the OnResize event does not occur:

  • embedded mode: plugin displays within the Web browser.
  • full-screen mode: plugin displays on top of all other applications.

If a change in size of the Silverlight plug-in triggers the OnFullScreenChange event, the OnResize event does not occur. In addition, the OnResize event does not occur when the Silverlight plug-in is in full-screen mode.

Note  Silverlight does not support automatic layout of elements. This means that applications have to provide logic to resize themselves appropriately when the plug-in's size changes.

Note    Use this event to make sizing decisions rather than OnLoad. 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. OnResize fires whenever the ActualHeight or ActualWidth properties change including when the plug-in first loads.

Examples

The following JavaScript example shows how to define a OnResize event for a Silverlight plug-in.

JavaScript
var plugin;
function onLoaded(sender, args)
{
    // Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();
    // Set the event handler function to the OnResize event.
    slPlugin.content.onResize = onResized;
    // Do initial layout of the app based on initial size.
    updateLayout(slPlugin.content.actualWidth, slPlugin.content.actualHeight);
}
function onResized(sender, eventArgs)
{
    // Do layout resizing of the app whenever the plug-in actualwidth or actualheight changes.
    updateLayout(slPlugin.content.actualWidth, slPlugin.content.actualHeight);
}
// Resize and reposition application elements.
function updateLayout(width, height)
{
    // Perform layout tasks based on width and height.
}

Applies To

Silverlight Plug-in

See Also

Resizing a Silverlight Plug-in
Silverlight Full-screen Support
ActualHeight
ActualWidth
OnFullScreenChange