共用方式為


FocusManager.GotFocus 事件

定義

發生于容器元素內的專案 (焦點範圍) 收到焦點時。 此事件會以非同步方式引發,因此焦點可能會在反升完成之前移動。

// Register
static event_token GotFocus(EventHandler<FocusManagerGotFocusEventArgs> const& handler) const;

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

// Revoke with event_revoker
static FocusManager::GotFocus_revoker GotFocus(auto_revoke_t, EventHandler<FocusManagerGotFocusEventArgs> const& handler) const;
public static event System.EventHandler<FocusManagerGotFocusEventArgs> GotFocus;
function onGotFocus(eventArgs) { /* Your code */ }
Microsoft.UI.Xaml.Input.FocusManager.addEventListener("gotfocus", onGotFocus);
Microsoft.UI.Xaml.Input.FocusManager.removeEventListener("gotfocus", onGotFocus);
- or -
Microsoft.UI.Xaml.Input.FocusManager.ongotfocus = onGotFocus;
Public Shared Custom Event GotFocus As EventHandler(Of FocusManagerGotFocusEventArgs) 

事件類型

備註

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

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

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

適用於

另請參閱