Share via


GetHost Method

Gets a reference to the Silverlight plug-in that contains the current element.

XAML
Cannot use methods in XAML.
Scripting
retval = object.GetHost()

Return Value

object

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

Remarks

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

Some of the object types listed in Applies To are abstract types, therefore this method cannot be truly called on that type in JavaScript because there is no way to obtain instances of abstract types in JavaScript programming.

Examples

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

JavaScript
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:

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

Applies To

Accessibility, ArcSegment, BeginStoryboard, BezierSegment, Boolean, Brush, Canvas, Color, ColorAnimation, ColorAnimationUsingKeyFrames, ColorKeyFrame, ColorKeyFrameCollection, DependencyObject, DiscreteColorKeyFrame, DiscreteDoubleKeyFrame, DiscretePointKeyFrame, DoubleAnimation, DoubleAnimationUsingKeyFrames, DoubleKeyFrame, DoubleKeyFrameCollection, Downloader, DrawingAttributes, Duration, Ellipse, EllipseGeometry, EventTrigger, Geometry, GeometryCollection, GeometryGroup, Glyphs, GradientStop, GradientStopCollection, Image, ImageBrush, InkPresenter, Inlines, KeySpline, KeyTime, Line, LinearColorKeyFrame, LinearDoubleKeyFrame, LinearGradientBrush, LinearPointKeyFrame, LineBreak, LineGeometry, LineSegment, Matrix, MatrixTransform, MediaAttribute, MediaAttributeCollection, MediaElement, Path, PathFigure, PathFigureCollection, PathGeometry, PathSegment, PathSegmentCollection, Point, PointAnimation, PointAnimationUsingKeyFrames, PointKeyFrame, PointKeyFrameCollection, PolyBezierSegment, Polygon, Polyline, PolyLineSegment, PolyQuadraticBezierSegment, QuadraticBezierSegment, RadialGradientBrush, Rect, Rectangle, RectangleGeometry, RepeatBehavior, ResourceDictionary, RotateTransform, Run, RuntimeErrorEventArgs, ScaleTransform, SkewTransform, SolidColorBrush, SplineColorKeyFrame, SplineDoubleKeyFrame, SplinePointKeyFrame, Storyboard, Stretch, Stroke, StrokeCollection, StylusInfo, StylusPoint, StylusPointCollection, TextBlock, Timeline, TimelineCollection, TimelineMarker, TimelineMarkerCollection, TimelineMarkerEventArgs, TimeSpan, TransformCollection, TransformGroup, TranslateTransform, TriggerActionCollection, TriggerCollection, VisualCollection, VideoBrush

See Also

Silverlight Object Models and Scripting to the Silverlight Plug-in