次の方法で共有


GetHost

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

Gets a reference to the Silverlight plug-in that contains the calling object.

retval = object.GetHost()

Return Value

Type: object

A reference to the Silverlight plug-in instance that contains the specified object.

Managed Equivalent

None

Remarks

The GetHost method can be used by any object (any DependencyObject) in the Silverlight object model to retrieve the Silverlight plug-in instance that contains the object. This method is especially useful for retrieving the Silverlight plug-in in an input event-handling function in which the sender parameter is generally a DependencyObject.

Some of the object types listed in the "Applies To" section of this topic are abstract types. This method cannot be truly called on those types in JavaScript, because there is no way to obtain instances of abstract types in JavaScript programming.

Example

The following JavaScript example shows how to retrieve a Silverlight plug-in object in a KeyUp event-handling function.

function onKeyUp(sender, keyEventArgs)
{
    // Determine whether the keystroke combination CTRL+V was detected.
    if ((keyEventArgs.key == 51) && (keyEventArgs.ctrl == true))
    {
        // Retrieve a reference to the plug-in.
        var plugin = sender.getHost();

        // Determine whether the 1.0 version of Silverlight is available.
        alert("Silverlight 1.0: " + plugin.isVersionSupported("1.0"));
    }
}

In cases where you need access to a plug-in's HTML Document Object Model (DOM) values, such as width and height, you can retrieve a reference to the HTML DOM representation of the Silverlight plug-in by using its ID value in the DOM for the HTML page. The following JavaScript example shows how to retrieve a reference to the Silverlight plug-in instance by using the document.getElementById method.

var plugin_1 = document.getElementById("SLPlugin_1");

Applies To

Accessibility Object (Silverlight JSAPI)

ArcSegment

BeginStoryboard

BezierSegment

BitmapImage (Silverlight 2)

Border (Silverlight 2)

Brush (abstract)

Canvas

Color

ColorAnimation

ColorAnimationUsingKeyFrames

ColorKeyFrame (abstract)

ColorKeyFrameCollection

DeepZoomImageTileSource (Silverlight 2)

DependencyObject (abstract)

DiscreteColorKeyFrame

DiscreteDoubleKeyFrame

DiscreteObjectKeyFrame (Silverlight 2)

DiscretePointKeyFrame

DoubleAnimation

DoubleAnimationUsingKeyFrames

DoubleKeyFrame (abstract)

DoubleKeyFrameCollection

Downloader

DrawingAttributes

Duration

Ellipse

EllipseGeometry

EventTrigger

Geometry (abstract)

GeometryCollection

GeometryGroup

Glyphs

GradientStop

GradientStopCollection

Image

ImageBrush

InkPresenter

Inlines

KeySpline

KeyTime

Line

LinearColorKeyFrame

LinearDoubleKeyFrame

LinearGradientBrush

LinearPointKeyFrame

LineBreak

LineGeometry

LineSegment

Matrix

MatrixTransform

MediaAttribute

MediaAttributeCollection

MediaElement

MultiScaleImage (Silverlight 2)

ObjectAnimationUsingKeyFrames (Silverlight 2)

ObjectKeyFrameCollection (Silverlight 2)

PasswordBox (Silverlight 2)

Path

PathFigure

PathFigureCollection

PathGeometry

PathSegment (abstract)

PathSegmentCollection

Point

PointAnimation

PointAnimationUsingKeyFrames

PointKeyFrame (abstract)

PointKeyFrameCollection

PolyBezierSegment

Polygon

Polyline

PolyLineSegment

PolyQuadraticBezierSegment

Popup (Silverlight 2)

QuadraticBezierSegment

RadialGradientBrush

Rect

Rectangle

RectangleGeometry

RepeatBehavior

ResourceDictionary

RotateTransform

Run

RuntimeErrorEventArgs

ScaleTransform

SkewTransform

SolidColorBrush

SplineColorKeyFrame

SplineDoubleKeyFrame

SplinePointKeyFrame

StackPanel (Silverlight 2)

Storyboard

Stroke

StrokeCollection

StylusInfo

StylusPoint

StylusPointCollection

TextBlock

TextBox (Silverlight 2)

Timeline (abstract)

TimelineCollection

TimelineMarker

TimelineMarkerCollection

TimelineMarkerEventArgs

TimeSpan

TransformCollection

TransformGroup

TranslateTransform

TriggerActionCollection

TriggerCollection

VisualCollection

VideoBrush