UIElement.OnLostFocus(RoutedEventArgs) Method


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

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



包含事件数据的 RoutedEventArgsA RoutedEventArgs that contains event data. 此事件数据必须包含 LostFocus 事件的标识符。This event data must contain the identifier for the LostFocus 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. 此实现不同于 * 实现中的某些其他 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF),后者仅提供一种简便的方法来为该事件添加类处理。This 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.

Notes to Inheritors

除非您有意且异常地需要不引发焦点事件,否则请确保您的实现调用基实现。Unless you have a deliberate and unusual need to not raise the focus events, make sure that your implementation calls the base implementation. 否则,在通常将焦点设置到此元素的典型用户操作期间,不会引发 LostFocus 事件。Otherwise, the LostFocus 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.

Applies to