Window.Activated 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當視窗成功啟用或停用時,會發生這種情況。
// Register
event_token Activated(TypedEventHandler<IInspectable, WindowActivatedEventArgs const&> const& handler) const;
// Revoke with event_token
void Activated(event_token const* cookie) const;
// Revoke with event_revoker
Window::Activated_revoker Activated(auto_revoke_t, TypedEventHandler<IInspectable, WindowActivatedEventArgs const&> const& handler) const;
public event TypedEventHandler<object,WindowActivatedEventArgs> Activated;
function onActivated(eventArgs) { /* Your code */ }
window.addEventListener("activated", onActivated);
window.removeEventListener("activated", onActivated);
- or -
window.onactivated = onActivated;
Public Custom Event Activated As TypedEventHandler(Of Object, WindowActivatedEventArgs)
事件類型
TypedEventHandler<IInspectable,WindowActivatedEventArgs>
範例
以下程式碼範例展示了此事件的典型使用模式。
void Window_Activated(object sender, WindowActivatedEventArgs e)
{
if (e.WindowActivationState == WindowActivationState.Deactivated)
{
// Show the "paused" UI.
VisualStateManager.GoToState(this, "PauseUI", false);
}
else if (e.WindowActivationState == WindowActivationState.PointerActivated
|| e.WindowActivationState == WindowActivationState.CodeActivated)
{
// Show the "active" UI.
VisualStateManager.GoToState(this, "ActivateUI", false);
}
}
備註
此事件發生 在視窗被 啟用或停用時。 你可以透過檢查 WindowActivationState 屬性來判斷啟用狀態Window。
如果系統的其他部分將焦點從窗戶移開,這個事件就會發生。 A Window 可以在螢幕上顯示,但不會主動。
視窗啟動可能因使用者互動或程式碼而發生,並 WindowActivationState 會顯示已發生的動作。