UIElement.GotFocus Event


在此元素获得逻辑焦点时发生。Occurs when this element gets logical focus.

 event System::Windows::RoutedEventHandler ^ GotFocus;
public event System.Windows.RoutedEventHandler GotFocus;
member this.GotFocus : System.Windows.RoutedEventHandler 
Public Custom Event GotFocus As RoutedEventHandler 


如果通过使用方法调用有意强制焦点,但上一个键盘焦点存在于不同的范围内,则逻辑焦点不同于键盘焦点。Logical focus differs from keyboard focus if focus is deliberately forced by using a method call but the previous keyboard focus exists in a different scope. 在这种情况下,键盘焦点将保留在该位置,并且调用 Focus 方法的元素仍会获得逻辑焦点。In this scenario, keyboard focus remains where it is and the element where a Focus method is called still gets logical focus.

此事件的更精确解释是:当路由中某个元素的 IsFocused 属性的值从 "false" 更改为 "true时,将引发此事件。A more precise interpretation of this event is that it is raised when the value of the IsFocused property of an element in the route is changed from false to true.

因为此事件使用冒泡路由,所以接收焦点的元素可能是一个子元素,而不是实际附加事件处理程序的元素。Because this event uses bubbling routing, the element that receives focus might be a child element instead of the element where the event handler is actually attached. 检查事件数据中的 Source,以确定获得焦点的实际元素。Check the Source in the event data to determine the actual element that gained focus.

路由事件信息Routed Event Information

标识符字段Identifier field GotFocusEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate RoutedEventHandler
  • 没有相应的隧道事件。There is no corresponding tunneling event.

  • 重写 OnGotFocus 在派生类中实现此事件的类处理。Override OnGotFocus to implement class handling for this event in derived classes.

Applies to

See also