Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement.OnGotFocus Method

Invoked whenever an unhandled GotFocus event reaches this element in its route.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

protected override void OnGotFocus(
	RoutedEventArgs e
)

Parameters

e
Type: System.Windows.RoutedEventArgs

The RoutedEventArgs that contains the event data.

Unlike some other On* methods exposed by the base elements, OnGotFocus does have a default implementation. Specifically, it has an implementation that overrides the null implementation in the next level of base element down, OnGotFocus. When invoked, OnGotFocus sets appropriate focus behavior on this element in cases where the event originated from the current element due to keyboard focus. The OnGotFocus handler does not mark the event arguments as handled, even when focus is set to the current element. If the event's source was another element in the tree (not the current element), the handler does nothing.

You can override this method in order to change the default focus behavior on your element, but be aware that changing focus behavior in this way might be better accomplished by not allowing the element to be focusable at all (see Focusable).

Notes to Inheritors

If you intend to mark the event handled in the arguments, you should be aware of consequences on event handling in other parent elements in the element tree. Because this handler acts on an event with a bubbling routing, setting the focus to the current sender per the event arguments may not be appropriate. Focus might need to go to either a composite child element or to a parent element, depending on the compositing of certain controls. Therefore marking a focus event as handled is only recommended if the entirety of the visual tree that the event is routing through is part of compositing of a control that you authored.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft