Window.Activated 事件

定義

當視窗成功啟動時發生。

public:
 virtual event WindowActivatedEventHandler ^ Activated;
// Register
event_token Activated(WindowActivatedEventHandler 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, WindowActivatedEventHandler const& handler) const;
public event WindowActivatedEventHandler Activated;
function onActivated(eventArgs) { /* Your code */ }
window.addEventListener("activated", onActivated);
window.removeEventListener("activated", onActivated);
- or -
window.onactivated = onActivated;
Public Custom Event Activated As WindowActivatedEventHandler 

事件類型

範例

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

void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
    if (e.WindowActivationState == 
        Windows.UI.Core.CoreWindowActivationState.Deactivated)
    {
        // Show the "paused" UI. 
        VisualStateManager.GoToState(this, "PauseUI", false);
    }
    else if (e.WindowActivationState == 
        Windows.UI.Core.CoreWindowActivationState.PointerActivated)
    {
        // Show the "active" UI. 
        VisualStateManager.GoToState(this, "ActivateUI", false);
    }
}

備註

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

適用於