Occurs when an object receives focus.
| XAML | <object GotFocus="eventhandlerFunction" .../> |
| Scripting |
[token = ]object.AddEventListener("GotFocus", eventhandlerFunction)
|
AddEventListener Parameters
| token | integer A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token. |
| eventhandlerFunction | object The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotes around the function name are not required. See Remarks. |
Event Handler Parameters
| sender | object Identifies the object that invoked the event. |
| eventArgs | object This parameter is always set to null. |
Examples
The following XAML example shows GotFocus and LostFocus events defined for the root Canvas object:
| XAML |
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
GotFocus="onGotFocus"
LostFocus="onLostFocus">
<TextBlock x:Name="myTextBlock" />
</Canvas>
|
The following JavaScript example shows how to implement GotFocus and LostFocus event handler functions. In this case, the text in the TextBlock changes when focus is received or lost:
| JavaScript |
function onGotFocus(sender, eventArgs)
{
sender.findName("myTextBlock").Text = "got focus";
}
function onLostFocus(sender, eventArgs)
{
sender.findName("myTextBlock").Text = "lost focus";
}
|
Applies To
Canvas
See Also
Silverlight Events
Silverlight Keyboard Support
LostFocus