Udostępnij za pośrednictwem


SilverlightHost Class

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

Reports details about the Silverlight-based application's instantiation settings, and exposes some of the HTML DOM values for the hosted Silverlight plug-in instance.

Inheritance Hierarchy

System.Object
  System.Windows.Interop.SilverlightHost

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

Syntax

'Declaration
Public Class SilverlightHost
public class SilverlightHost

The SilverlightHost type exposes the following members.

Constructors

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

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Background Gets the background color value that was applied to the Silverlight plug-in as part of instantiation settings.
Public propertySupported by Silverlight for Windows Phone Content Gets the "Content" sub-object of this SilverlightHost.
Public property InitParams Gets the initialization parameters that were passed as part of HTML initialization of a Silverlight plug-in.
Public propertySupported by Silverlight for Windows Phone IsLoaded Gets a value that indicates whether the hosted Silverlight plug-in has finished loading.
Public propertySupported by Silverlight for Windows Phone NavigationState Gets or sets a URI fragment that represents the current navigation state.
Public propertySupported by Silverlight for Windows Phone Settings Gets the "Settings" sub-object of this SilverlightHost.
Public property Source Gets the URI of the package or XAML file that specifies the XAML content to render.

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.)
Public methodSupported by Silverlight for Windows Phone IsVersionSupported Returns a value that indicates whether the installed Silverlight plug-in supports the specified version.
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 eventSupported by Silverlight for Windows Phone NavigationStateChanged Occurs when the NavigationState property changes value.

Top

Remarks

Much of the information that is reported by a SilverlightHost object is the same information that could be obtained from properties of the Silverlight plug-in object in the JavaScript API of the Silverlight object model. For instance, the Background color that was set as part of the Silverlight plug-in instantiation can be obtained by getting the current SilverlightHost instance from the Application.Host property, and then getting the Background property.

The Content property returns a value of type Content, which represents the visual state of the plug-in. This type enables you to perform common tasks, such as display the plug-in in full-screen mode or retrieve its current size.

The Settings property returns a value of type Settings, which provides access to some plug-in configuration values.

Examples

The following code example demonstrates how to use this class.

' The Host object, which represents the host Silverlight plug-in. 
Dim host As System.Windows.Interop.SilverlightHost = _
    Application.Current.Host

' The following code demonstrates how to use the Host object 
' to access other APIs in the System.Windows.Interop namespace. 

' The IsVersionSupported method. This method is useful when 
' you want to implement an upgrade experience in managed code. 
Dim isSupported As Boolean = host.IsVersionSupported("2.0.30908.0")

' Read-only properties of the Host object. 
Dim pluginBackground As System.Windows.Media.Color = host.Background
Dim loaded As Boolean = host.IsLoaded
Dim source As Uri = host.Source

' The Settings object, which represents Web browser settings. 
Dim settings As System.Windows.Interop.Settings = host.Settings

' Read/write properties of the Settings object. 
settings.EnableFrameRateCounter = True
settings.EnableRedrawRegions = True
settings.MaxFrameRate = 60

' Read-only properties of the Settings object. 
Dim windowless As Boolean = settings.Windowless
Dim htmlAccessEnabled As Boolean = settings.EnableHTMLAccess

' The Content object, which represents the plug-in display area. 
Dim content As System.Windows.Interop.Content = host.Content

' The read/write IsFullScreen property of the Content object. 
' See also the Content.FullScreenChanged event. 
Dim isFullScreen As Boolean = content.IsFullScreen

' Read-only properties of the Content object. These properties do 
' not contain meaningful values until after the Content.Resized 
' event occurs for the first time. 
Dim actualWidth As Double = content.ActualWidth
Dim actualHeight As Double = content.ActualHeight
// The Host object, which represents the host Silverlight plug-in.
System.Windows.Interop.SilverlightHost host = 
    Application.Current.Host;

// The following code demonstrates how to use the Host object
// to access other APIs in the System.Windows.Interop namespace.

// The IsVersionSupported method. This method is useful when
// you want to implement an upgrade experience in managed code.
bool isSupported = host.IsVersionSupported("2.0.30908.0");

// Read-only properties of the Host object.
System.Windows.Media.Color pluginBackground = host.Background;
bool loaded = host.IsLoaded;
Uri source = host.Source;

// The Settings object, which represents Web browser settings.
System.Windows.Interop.Settings settings = host.Settings;

// Read/write properties of the Settings object.
settings.EnableFrameRateCounter = true;
settings.EnableRedrawRegions = true;
settings.MaxFrameRate = 60;

// Read-only properties of the Settings object.
bool windowless = settings.Windowless;
bool htmlAccessEnabled = settings.EnableHTMLAccess;

// The Content object, which represents the plug-in display area.
System.Windows.Interop.Content content = host.Content;

// The read/write IsFullScreen property of the Content object.
// See also the Content.FullScreenChanged event.
bool isFullScreen = content.IsFullScreen;

// Read-only properties of the Content object. These properties do 
// not contain meaningful values until after the Content.Resized 
// event occurs for the first time. 
double actualWidth = content.ActualWidth;
double actualHeight = content.ActualHeight;

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.