Export (0) Print
Expand All

Content.ActualWidth Property

Silverlight

Gets the browser-determined width of the Silverlight plug-in content area.

Namespace:  System.Windows.Interop
Assembly:  System.Windows (in System.Windows.dll)

public double ActualWidth { get; }

Property Value

Type: System.Double
The browser-determined width, in pixels, of the Silverlight plug-in content area. The default value is the width of the Silverlight plug-in, as specified by the HTML object element that instantiated it.

Important noteImportant Note:

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

The primary scenario where ActualWidth might be unknown, even to the caller that instantiated the plug-in, is when the initial width value is specified as a percentage. In this case the browser must calculate a pixel width value, and ActualWidth returns that value. Also, a Silverlight plug-in can display in either embedded mode or full-screen mode:

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

  • In full-screen mode, the plug-in resizes to the current resolution of the screen and 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 a fixed 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 value, such as "300", 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 as determined by the browser. In this case, resizing the browser window size 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 screen.

The Resized 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 Resized event does not occur. However, when full-screen mode is first entered, the FullScreenChanged event is raised.

The following code example demonstrates how to use this property.


Page rootPage = new Page();
private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = rootPage;

    rootPage.LayoutRoot.MouseLeftButtonDown +=
        delegate(Object s, MouseButtonEventArgs args) {
            this.Host.Content.IsFullScreen =
                !this.Host.Content.IsFullScreen;
        };

    this.Host.Content.FullScreenChanged += 
        new EventHandler(DisplaySizeInformation);

    this.Host.Content.Resized += 
        new EventHandler(DisplaySizeInformation);
}

private void DisplaySizeInformation(Object sender, EventArgs e)
{
    String message = String.Format(
        "ActualWidth={0}, ActualHeight={1}",
        this.Host.Content.ActualWidth,
        this.Host.Content.ActualHeight);

    rootPage.LayoutRoot.Children.Clear();
    rootPage.LayoutRoot.Children.Add(
        new TextBlock { Text = message });
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft