In Silverlight version 1.0, only the root of the object tree was focusable. In Silverlight version 2, any UIElement is focusable.
The GotFocus event is a bubbling event. This means that if multiple GotFocus event handlers are registered for a sequence of objects connected by parent-child relationships in the object tree, the event is received by each object in that relationship. The event is raised by the object that directly receives the input condition that initiates the event, and then bubbles to each successive parent object. The bubbling metaphor indicates that the event starts at the bottom and works its way up the object tree. For a bubbling event, the sender available to the event handler identifies the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event. To get the object that initiated the event, use the Source value of the event's RoutedEventArgs event data.
When you handle the GotFocus or LostFocus events, there is no Handled property available in the event data class for Silverlight 2 Beta 2, and the event will continue to route upwards through the object tree and invoke all attached handlers. This might not always be desirable for your application's handling strategy for focus events, if you want to handle focus at various levels in your object tree. You might consider one of the following techniques:
Use a Boolean flag variable to record focusing state. Set your own "Handled" variable to true from the specific handler call that your design deems has appropriately handled the event. Check this "Handled" variable in further handlers to check whether some other handler has already acted, and if so take no action. At the root of the object tree, handle the focus event at least for the purpose of setting "Handled" back to false to reset the state for the next focus event.
Place particular emphasis on checking or using the object values transmitted to the handler by sender and by Source in the event data. You might choose to act only if sender equals Source , or if sender is a particular named object in cases when the same focus event handler is attached to multiple objects, or similar logical operations.
GotFocus is not raised if Focus is called on the object but the object already had focus.
GotFocus is raised asynchronously versus the actual focus shift, because of the design of the Silverlight focus system.