FrameworkElement.OnGotFocus(RoutedEventArgs) FrameworkElement.OnGotFocus(RoutedEventArgs) FrameworkElement.OnGotFocus(RoutedEventArgs) FrameworkElement.OnGotFocus(RoutedEventArgs) Method

定義

當未處理的 GotFocus 事件到達其路由中的這個項目時,便會叫用此方法。Invoked whenever an unhandled GotFocus event reaches this element in its route.

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

參數

e
RoutedEventArgs RoutedEventArgs RoutedEventArgs RoutedEventArgs

包含事件資料的 RoutedEventArgsThe RoutedEventArgs that contains the event data.

備註

不同於在某些其他 * 基底的項目,所公開的方法OnGotFocus沒有預設實作。Unlike some other On* methods exposed by the base elements, OnGotFocus does have a default implementation. 具體來說,它已關閉,就會覆寫基底元素的下一步 層級中的 null 實作的實作OnGotFocusSpecifically, it has an implementation that overrides the null implementation in the next level of base element down, OnGotFocus. 叫用時,OnGotFocus在目前的項目,因為鍵盤焦點從事件的起源的情況下此項目上設定適當的焦點行為。When invoked, OnGotFocus sets appropriate focus behavior on this element in cases where the event originated from the current element due to keyboard focus. OnGotFocus處理常式不會標記為已處理,即使當焦點設定為目前的項目之事件引數。The OnGotFocus handler does not mark the event arguments as handled, even when focus is set to the current element. 如果事件的來源是在樹狀目錄中 (不是目前項目) 的另一個項目,這個處理常式沒有任何作用。If the event's source was another element in the tree (not the current element), the handler does nothing.

您可以覆寫此方法,以變更預設的焦點行為,在您的項目,但請注意,變更焦點行為,如此一來可能會更好可藉由不允許 完全可設定焦點的項目 (請參閱Focusable)。You can override this method in order to change the default focus behavior on your element, but be aware that changing focus behavior in this way might be better accomplished by not allowing the element to be focusable at all (see Focusable).

給繼承者的注意事項

如果您想要將事件引數中處理標記,您應留意其他項目樹狀結構中的父元素中的事件處理的結果。If you intend to mark the event handled in the arguments, you should be aware of consequences on event handling in other parent elements in the element tree. 因為這個處理常式是事件反昇的路由,將焦點設定至目前sender每個事件引數可能不適當。Because this handler acts on an event with a bubbling routing, setting the focus to the current sender per the event arguments may not be appropriate. 焦點,可能需要進入任一個複合的子項目或父項目,根據某些控制項的複合。Focus might need to go to either a composite child element or to a parent element, depending on the compositing of certain controls. 因此將焦點事件標示為已處理,才建議整個事件透過路由的視覺化樹狀結構是撰寫您所撰寫之控制項的一部分。Therefore marking a focus event as handled is only recommended if the entirety of the visual tree that the event is routing through is part of compositing of a control that you authored.

適用於

另請參閱