次の方法で共有


Content Class

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

Reports details about the instantiation settings of a-based application, and exposes some of the HTML DOM values for the hosted Silverlight plug-in instance. The Content object contains APIs that specifically relate to the Silverlight content area (the area that is declared by the width and height in the initialization).

Inheritance Hierarchy

System.Object
  System.Windows.Interop.Content

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

Syntax

'Declaration
Public NotInheritable Class Content
public sealed class Content

The Content type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone Content Infrastructure. Initializes a new instance of the Content class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone ActualHeight Gets the browser-determined height of the Silverlight plug-in content area.
Public propertySupported by Silverlight for Windows Phone ActualWidth Gets the browser-determined width of the Silverlight plug-in content area.
Public property FullScreenOptions Gets or sets a value that indicates the behavior of full-screen mode.
Public property IsFullScreen Gets or sets a value that indicates whether the Silverlight plug-in is displaying in full-screen mode.
Public property ZoomFactor Gets the factor by which the current browser window resizes its contents.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Events

  Name Description
Public event FullScreenChanged Occurs when the hosted Silverlight plug-in either enters or exits full-screen mode.
Public eventSupported by Silverlight for Windows Phone Resized Occurs when the ActualHeight or the ActualWidth of the Silverlight plug-in change.
Public event Zoomed Occurs when the zoom setting in the host browser window changes or is initialized.

Top

Remarks

This object is always the value of the Content property of a parent SilverlightHost, and this is the only context in which a Content object is used.

Examples

The following code example demonstrates how to use this class in a variety of ways.

Private WithEvents rootPage As Page = New Page()
Private WithEvents htmlContent As Content
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
    Me.RootVisual = rootPage
    htmlContent = Me.Host.Content
End Sub

Private Sub ToggleFullScreen(ByVal sender As Object, _
    ByVal e As MouseButtonEventArgs) Handles rootPage.MouseLeftButtonDown
    Me.Host.Content.IsFullScreen = Not Me.Host.Content.IsFullScreen
End Sub

Private Sub DisplaySizeInformation( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles htmlContent.FullScreenChanged, htmlContent.Resized

    Dim message As String = String.Format( _
        "ActualWidth={0}, ActualHeight={1}", _
        Me.Host.Content.ActualWidth, _
        Me.Host.Content.ActualHeight)

    rootPage.LayoutRoot.Children.Clear()
    Dim t As New TextBlock()
    t.Text = message
    rootPage.LayoutRoot.Children.Add(t)

End Sub
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 });
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.