UIElement.OnGotFocus(RoutedEventArgs) 方法

定义

使用所提供的事件数据引发 GotFocus 路由事件。Raises the GotFocus routed event by using the event data provided.

protected:
 virtual void OnGotFocus(System::Windows::RoutedEventArgs ^ e);
protected virtual void OnGotFocus (System.Windows.RoutedEventArgs e);
abstract member OnGotFocus : System.Windows.RoutedEventArgs -> unit
override this.OnGotFocus : System.Windows.RoutedEventArgs -> unit
Protected Overridable Sub OnGotFocus (e As RoutedEventArgs)

参数

e
RoutedEventArgs

包含事件数据的 RoutedEventArgsA RoutedEventArgs that contains event data. 此事件数据必须包含 GotFocus 事件的标识符。This event data must contain the identifier for the GotFocus event.

注解

虽然虚拟,但这种方法具有引发事件的默认实现。This method, although virtual, does have a default implementation that raises the event.

此 On * 方法实现旨在引发事件,并在内部调用此相同的方法实现,以便在 IsFocused 属性值更改时引发事件。This On* method implementation is intended to raise the event, and this same method implementation is invoked internally to raise the event when the IsFocused property value changes. OnGotFocus 实现不同于一些其他 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) On * 实现,后者仅提供一种简便的方法来为该事件添加类处理。The OnGotFocus implementation differs from some other Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) On* implementations, which only provide a convenient way to add class handling for that event.

继承者说明

除非您有意且异常地需要不引发焦点事件,否则请确保您的实现调用基实现。Unless you have a deliberate and unusual need to not raise the focus events, make sure that your implementation calls the base implementation. 否则,在通常将焦点设置到此元素的典型用户操作期间,不会引发 GotFocus 事件。Otherwise, the GotFocus event is not raised during typical user operations that ordinarily set focus to this element. 如果你不想让你的元素成为可设定焦点的元素,则可以通过将 Focusable 设置为 false来防止元素获得焦点。If you do not intend your element to be focusable, you can prevent the element from being focusable by setting Focusable to false.

适用于

另请参阅