Export (0) Print
Expand All

Content.ActualHeight Property

Silverlight

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

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

public double ActualHeight { get; }

Property Value

Type: System.Double
The browser-determined height, in pixels, of the Silverlight plug-in content area. The default value is the height, in pixels, 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 ActualHeight might be unknown, even to the caller that instantiated the plug-in, is when the initial height value is specified as a percentage. In this case the browser must calculate a pixel height value, and ActualHeight 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 ActualHeight depends on whether the height of the Silverlight plug-in is a fixed or percentage value. The height of the Silverlight plug-in is defined in the OBJECT tag of the containing Web page. If the height of the Silverlight plug-in is a fixed value, such as "300", ActualHeight is set to the plug-in height. If the height of the Silverlight plug-in is a percentage value, such as "100%", ActualHeight is set to the most appropriate height for displaying a browser plug-in. In this case, resizing the browser window height causes the ActualHeight value to change.

When the application is in full-screen mode, the value of ActualHeight is set to the current vertical 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:
© 2015 Microsoft