Share via


InputActivationListener Class

Definition

Provides the ability to access and observe changes to the activation state of an object.

public ref class InputActivationListener sealed : InputObject
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65537)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class InputActivationListener final : InputObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65537)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class InputActivationListener : InputObject
Public NotInheritable Class InputActivationListener
Inherits InputObject
Inheritance
Object Platform::Object IInspectable InputObject InputActivationListener
Attributes

Examples

The following Windows App SDK example shows how to respond to activation events for an Microsoft.UI.Windowing.AppWindow object:

class RespondToAppWindowActivation
{
    InputActivationListener inputActivationListener;

    public RespondToAppWindowActivation(Microsoft.UI.Windowing.AppWindow appWindow)
    {
        inputActivationListener = InputActivationListener.GetForWindowId(appWindow.Id);

        inputActivationListener.InputActivationChanged += OnActivationChanged;
    }

    void OnActivationChanged(
        InputActivationListener sender,
        InputActivationListenerActivationChangedEventArgs args)
    {
        if (sender.State == InputActivationState.Activated)
        {
            System.Diagnostics.Debug.WriteLine("AppWindow was activated.");

            LeaveMyBackgroundMode();
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("AppWindow was deactivated.");

            EnterMyBackgroundMode();
        }
    }
}

Remarks

If the object associated with an InputActivationListener is destroyed, the InputActivationListener object will be implicitly disposed. See InputObject for more detail.

Properties

DispatcherQueue

Gets the DispatcherQueue for the InputObject.

(Inherited from InputObject)
State

Gets the activation state of the object.

Methods

GetForIsland(ContentIsland)

Retrieves an InputActivationListener object for the specified ContentIsland.

GetForWindowId(WindowId)

Retrieves a InputActivationListener object for the specified top-level window.

Events

InputActivationChanged

Occurs when the input activation state of the associated object changes.

Applies to

See also