KeyboardFocusChangedEventArgs Class
Provides data for UIElement::LostKeyboardFocus and UIElement::GotKeyboardFocus routed events, as well as related attached and Preview events.
System::EventArgs
System.Windows::RoutedEventArgs
System.Windows.Input::InputEventArgs
System.Windows.Input::KeyboardEventArgs
System.Windows.Input::KeyboardFocusChangedEventArgs
Assembly: PresentationCore (in PresentationCore.dll)
The KeyboardFocusChangedEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | KeyboardFocusChangedEventArgs | Initializes a new instance of the KeyboardFocusChangedEventArgs class. |
| Name | Description | |
|---|---|---|
![]() | Device | Gets the input device that initiated this event. (Inherited from InputEventArgs.) |
![]() | Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. (Inherited from RoutedEventArgs.) |
![]() | KeyboardDevice | Gets the keyboard device associated with the input event. (Inherited from KeyboardEventArgs.) |
![]() | NewFocus | Gets the element that focus has moved to. |
![]() | OldFocus | Gets the element that previously had focus. |
![]() | OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. (Inherited from RoutedEventArgs.) |
![]() | RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. (Inherited from RoutedEventArgs.) |
![]() | Source | Gets or sets a reference to the object that raised the event. (Inherited from RoutedEventArgs.) |
![]() | Timestamp | Gets the time when this event occurred. (Inherited from InputEventArgs.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InvokeEventHandler | Invokes event handlers in a type-specific way, which can increase event system efficiency. (Overrides KeyboardEventArgs::InvokeEventHandler(Delegate, Object).) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | OnSetSource | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. (Inherited from RoutedEventArgs.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
This event data class is used with the following attached events:
This event data class is also used with the following routed events on base elements. These routed events forward the previously listed attached events to make them more accessible to the general element model in WPF.
The attached events and the base element routed events share their event data, and the bubbling and tunneling versions of the routed events also share event data. This can affect the handled characteristics of the event as it travels the event route. For details, see Input Overview.
If the PreviewGotKeyboardFocus event or the PreviewLostKeyboardFocus event is handled (Handled is set to true in the event data), keyboard focus will not change.
If the PreviewGotKeyboardFocus event or the PreviewLostKeyboardFocus event is handled, keyboard focus will not change.
This example shows how to change the color of an element when it gains and loses focus by using the GotFocus and LostFocus events.
This example consists of a Extensible Application Markup Language (XAML) file and a code-behind file.
The following XAML creates the user interface, which consists of two Button objects, and attaches event handlers for the GotFocus and LostFocus events to the Button objects.
<StackPanel> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Height" Value="20"/> <Setter Property="Width" Value="250"/> <Setter Property="HorizontalAlignment" Value="Left"/> </Style> </StackPanel.Resources> <Button GotFocus="OnGotFocusHandler" LostFocus="OnLostFocusHandler">Click Or Tab To Give Keyboard Focus</Button> <Button GotFocus="OnGotFocusHandler" LostFocus="OnLostFocusHandler">Click Or Tab To Give Keyborad Focus</Button> </StackPanel>
The following code behind creates the GotFocus and LostFocus event handlers. When the Button gains keyboard focus, the Background of the Button is changed to red. When the Button loses keyboard focus, the Background of the Button is changed back to white.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
