GetHost Method
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Gets a reference to the containing Silverlight control.
XAML |
You cannot use methods in XAML.
|
Scripting |
value = object.getHost()
|
Parameters
None
Return Value
A reference to the Silverlight control that contains the specified object.
Remarks
The GetHost method can be used by any UIElement-derived object to retrieve the Silverlight control that contains the object. This method is especially useful for retrieving the Silverlight control in an event handling function, in which the sender parameter identifies a UIElement-derived object.
The following JavaScript example shows how to retrieve a Silverlight control 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 control. var control = sender.getHost(); // Display the current version of the control. alert("Silverlight version: " + control.settings.version); } } |
In cases where you need access to a control's Document Object Model (DOM) values, such as width and height, you can retrieve a reference to the Silverlight control by using its id value in the DOM for the Web page. The following JavaScript example shows how to retrieve a reference to the Silverlight control by using the document.getElementById method:
JavaScript |
---|
var control = document.getElementById("myControl"); |