ContentElement.OnLostKeyboardFocus(KeyboardFocusChangedEventArgs) 方法


当某个未处理的 LostKeyboardFocus 附加事件在其路由中到达派生自此类的某个元素时调用。Invoked when an unhandled LostKeyboardFocus attached event reaches an element in its route that is derived from this class. 实现此方法可为此事件添加类处理。Implement this method to add class handling for this event.

protected public:
 virtual void OnLostKeyboardFocus(System::Windows::Input::KeyboardFocusChangedEventArgs ^ e);
protected internal virtual void OnLostKeyboardFocus (System.Windows.Input.KeyboardFocusChangedEventArgs e);
abstract member OnLostKeyboardFocus : System.Windows.Input.KeyboardFocusChangedEventArgs -> unit
override this.OnLostKeyboardFocus : System.Windows.Input.KeyboardFocusChangedEventArgs -> unit
Protected Friend Overridable Sub OnLostKeyboardFocus (e As KeyboardFocusChangedEventArgs)



包含事件数据的 KeyboardFocusChangedEventArgsThe KeyboardFocusChangedEventArgs that contains event data.


此方法没有默认实现。This method has no default implementation. 因为继承中的中间类可能实现此方法,所以建议您在实现中调用基实现。Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

此方法的用途类似于 公共语言运行时 (CLR)common language runtime (CLR) 方法的事件模式 * :此方法提供了通过建立类处理程序而不是实例处理程序来处理来自派生类的匹配事件的方法。The purpose of this method is similar to the 公共语言运行时 (CLR)common language runtime (CLR) event pattern On* methods: this method provides the means to handle the matching event from derived classes by establishing a class handler instead of an instance handler. 在这种情况下,匹配事件是路由事件。In this case the matching event is a routed event. *对于路由事件,On 方法的实现模式是不同的,因为路由事件可以由子元素引发,这不一定是将调用处理程序的元素。The implementation pattern of the On* methods is different for routed events because a routed event can be raised by a child element, which is not necessarily the element that will invoke handlers. 因此,您的实现需要检查事件数据的源属性。Therefore, your implementation needs to examine the source properties of the event data. 大多数情况下,它不应尝试 reraise 该事件。It should not try to reraise the event in most cases.

通过重写此方法或使用注册类处理程序 RegisterClassHandlerContentElement 可以在事件路由中收到事件时调用私有类处理程序方法。Either by overriding this method or by registering class handlers with RegisterClassHandler, derived classes of ContentElement can call private class handler methods when the event is received along the event route. 适用于类处理的一种情况是操作事件数据,并将路由事件标记为 "已处理"。One scenario where class handling is appropriate is to manipulate the event data and mark the routed event as handled.