Window.Activated 事件

定義

當視窗已成功啟動時發生。

// 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) 

事件類型

範例

下列程式碼範例示範此事件的一般使用模式。

void Current_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);
    }
}

備註

當系統已啟動或停用 Window 時,就會發生此事件。 應用程式可以藉由檢查WindowActivationState屬性來判斷啟用的狀態 WindowWindow例如,在貼齊的應用程式) 中,畫面上可能會顯示 ,但無法使用 (。 此外,如果系統的任何其他部分會離開視窗,就會發生此事件。 這可能會因為使用者互動或程式碼而發生,而且 WindowActivationState 會指出已採取哪些動作。

適用於

另請參閱