다음을 통해 공유


Window.Activated Event

Definition

Occurs when the window has been successfully activated or deactivated.

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

Event Type

Examples

The following code example demonstrates a typical usage pattern for this event.

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

Remarks

This event occurs when a Window has been activated or deactivated. You can determine the status of the Window activation by checking the WindowActivationState property.

If any other part of the system takes focus away from the window, this event will occur. A Window can be visible on screen but not be active.

Window activation can happen as a result of user interaction or code, and the WindowActivationState will indicate which action has taken place.

Applies to

See also