Sdílet prostřednictvím


ActualWidth (Silverlight Plug-in)

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

Gets the width of the rendering area of the Microsoft Silverlight plug-in.

value = silverlightObject.content.ActualWidth

Property Value

Type: integer

The width of the rendering area of the Silverlight plug-in, in pixels.

This property is read-only. The default value is the width of the Silverlight plug-in, as specified by the OBJECT/EMBED tag that instantiated it. If width was specified by percentage during initialization, this is a calculated pixel value.

Managed Equivalent

ActualWidth

Remarks

See also ActualWidth (Silverlight Plug-in Object). ActualWidth is the JavaScript / DOM exposure of a common value of the plug-in object, which can be accessed by a number of programming models, including managed code and COM.

This property is available on the content subobject of a Silverlight plug-in instance.

Important noteImportant Note:

In the early stages of the object lifetime of a Silverlight plug-in instance, ActualHeight and ActualWidth do not contain a usable value. In particular, the OnLoad event does not yet guarantee a correct value for ActualHeight or ActualWidth. In general, you should check these values in the handler for the OnResize event, which occurs just after OnLoad.

A Silverlight plug-in can display in either embedded mode or full-screen mode:

  • In embeddedmode, the plug-in displays in the Web browser window.

  • In full-screen mode, the plug-in displays on top of all other applications.

When the Silverlight plug-in is in embedded mode, the value of ActualWidth depends on whether the width of the Silverlight plug-in is specified as a fixed-width or percentage value. The width of the Silverlight plug-in is defined in the OBJECT tag of the containing Web page. If the width of the Silverlight plug-in is a fixed-width value, such as "400", ActualWidth is set to the plug-in width. If the width of the Silverlight plug-in is a percentage value, such as "100%", ActualWidth is set to the most appropriate width for displaying the plug-in in the browser. In this case, resizing the browser window width causes the ActualWidth value to change.

When the application is in full-screen mode, the value of ActualWidth is set to the current horizontal resolution of the display.

The OnResize event occurs whenever the ActualHeight and ActualWidth properties change, and the Silverlight plug-in is in embedded mode. When the Silverlight plug-in is in full-screen mode, the OnResize event does not occur.

Example

The following JavaScript example shows how to use the ActualWidth and ActualHeight properties. In the case where width is defined as a percentage value, the ActualWidth value represents a numeric width value, interpreted in pixels.

function onResizeStatus(sender, eventArgs)
{
    // Concatenate the size values as a formatted message string.
    var msgString  = " actualWidth: " + slPlugin.content.actualWidth;
        msgString += " actualHeight: " + slPlugin.content.actualHeight;

    // Display an alert dialog box with a formatted message string.
    var textBlock = sender.findName("Status");
    textBlock.text = msgString;
}

Applies To

Silverlight Plug-in