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)
BitmapImage (Silverlight 2)
Border (Silverlight 2)
Brush (abstract)
ColorKeyFrame (abstract)
DeepZoomImageTileSource (Silverlight 2)
DependencyObject (abstract)
DiscreteObjectKeyFrame (Silverlight 2)
DoubleKeyFrame (abstract)
Geometry (abstract)
MultiScaleImage (Silverlight 2)
ObjectAnimationUsingKeyFrames (Silverlight 2)
ObjectKeyFrameCollection (Silverlight 2)
PasswordBox (Silverlight 2)
PathSegment (abstract)
PointKeyFrame (abstract)
Popup (Silverlight 2)
StackPanel (Silverlight 2)
TextBox (Silverlight 2)
Timeline (abstract)