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 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 将指示已执行哪些操作。

适用于

另请参阅