共用方式為


FocusManager.GettingFocus 事件

定義

發生在專案實際接收焦點之前。 此事件會同步引發,以確保事件反升時不會移動焦點。

// Register
static event_token GettingFocus(EventHandler<GettingFocusEventArgs> const& handler) const;

// Revoke with event_token
static void GettingFocus(event_token const* cookie) const;

// Revoke with event_revoker
static FocusManager::GettingFocus_revoker GettingFocus(auto_revoke_t, EventHandler<GettingFocusEventArgs> const& handler) const;
public static event System.EventHandler<GettingFocusEventArgs> GettingFocus;
function onGettingFocus(eventArgs) { /* Your code */ }
Microsoft.UI.Xaml.Input.FocusManager.addEventListener("gettingfocus", onGettingFocus);
Microsoft.UI.Xaml.Input.FocusManager.removeEventListener("gettingfocus", onGettingFocus);
- or -
Microsoft.UI.Xaml.Input.FocusManager.ongettingfocus = onGettingFocus;
Public Shared Custom Event GettingFocus As EventHandler(Of GettingFocusEventArgs) 

事件類型

備註

建議您盡可能使用 UIElement 焦點路由事件,而不是 FocusManager 事件。

FocusNavigationDirection.PreviousFocusNavigationDirection.Next 無法搭配 FindNextElementOptions使用。 只有 FocusNavigationDirection.UpFocusNavigationDirection.DownFocusNavigationDirection.LeftFocusNavigationDirection.Right 有效。

UIElement 焦點事件會依下列順序反升至 FocusManager:

  1. UIElement.LosingFocus/FocusManager.LosingFocus
  2. UIElement.GettingFocus/FocusManager.GettingFocus
  3. UIElement.LostFocus 路由事件是由遺失焦點的專案引發,而事件會反升
  4. 即使路由事件標示為已處理) ,也會引發 FocusManager.LostFocus (
  5. UIElement.GotFocus 路由事件是由接收焦點的專案引發,而事件會反升
  6. 即使路由事件標示為已處理) ,也會引發 FocusManager.GotFocus (

適用於

另請參閱