Aracılığıyla paylaş


OnResize

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

Establishes the handler for the Resized event that occurs whenever the ActualHeight or ActualWidth property of the Silverlight plug-in changes.

<object ...>
  <param name="onresize" value="scriptHandlerName" />
...
</object>
value = silverlightObject.content.OnResize
silverlightObject.content.OnResize = scriptHandlerName

Arguments

sender

object

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

eventArgs

object

This parameter is always set to null.

Managed Equivalent

Content.Resized

Remarks

The Resized event occurs whenever the Silverlight plug-in changes its ActualHeight or ActualWidth property in embedded mode.

If a change in size of the Silverlight plug-in triggers the FullScreenChanged event you handle with OnFullScreenChanged, the Resized event does not occur. In addition, the Resized event does not occur when the Silverlight plug-in is in full-screen mode.

In embedded mode, the plug-in displays in the Web browser window. In full-screen mode, the plug-in displays on top of all other applications.

NoteNote:

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

NoteNote:

Handle with OnResize event instead of OnLoad to make sizing decisions. This is because the actualHeight and actualWidth values of the Silverlight plug-in are not guaranteed to be set at the time the Loaded event occurs. Resize occurs whenever the ActualHeight or ActualWidth properties change, including when the plug-in first loads.

Example

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

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 application based on initial size.
    updateLayout(slPlugin.content.actualWidth, slPlugin.content.actualHeight);
}

function onResized(sender, eventArgs)
{
    // Do layout resizing of the application 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