CoreWindow CoreWindow CoreWindow Class

Definition

Represents the Windows Store app with input events and basic user interface behaviors.

public sealed class CoreWindowpublic sealed class CoreWindowPublic NotInheritable Class CoreWindow
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

New instances of this class are obtained by calling CoreApplication.CreateNewView and then inspecting the CoreWindow property on the returned CoreApplicationView instance. Or you can obtain existing CoreWindow instances for a running app from the CoreApplication.Views property, or by calling CoreWindow.GetForCurrentThread, as seen in the following example.

void MyCoreWindowEvents::Run() // this is an implementation of IFrameworkView::Run() used to show context
{
    CoreWindow::GetForCurrentThread()->Activate();

    /...

    CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}
Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX).

Properties

AutomationHostProvider AutomationHostProvider AutomationHostProvider AutomationHostProvider

Gets the automation provider assigned to this window.

public object AutomationHostProvider { get; }public object AutomationHostProvider { get; }Public ReadOnly Property AutomationHostProvider As objectpublic object AutomationHostProvider { get; }
Value
object object object

The automation provider for this window.

Attributes

Bounds Bounds Bounds Bounds

Gets the bounding rectangle of the window.

public Rect Bounds { get; }public Rect Bounds { get; }Public ReadOnly Property Bounds As Rectpublic Rect Bounds { get; }
Value
Rect Rect Rect

The bounding rectangle of the window, in device-independent pixels (DIPs).

Attributes

Remarks

To convert from DIPs to physical pixels (and back), use these equations (where DPI is the dots per inch value for the screen):

  • DIP value = (physical pixel x 96) / DPI
  • physical pixel value = (DIP x DPI) / 96

CustomProperties CustomProperties CustomProperties CustomProperties

Gets the set of custom properties for the window.

public IPropertySet CustomProperties { get; }public IPropertySet CustomProperties { get; }Public ReadOnly Property CustomProperties As IPropertySetpublic IPropertySet CustomProperties { get; }
Value
IPropertySet IPropertySet IPropertySet

The set of custom properties for the window, represented as tuples.

Attributes

Dispatcher Dispatcher Dispatcher Dispatcher

Gets the event dispatcher for the window.

public CoreDispatcher Dispatcher { get; }public CoreDispatcher Dispatcher { get; }Public ReadOnly Property Dispatcher As CoreDispatcherpublic CoreDispatcher Dispatcher { get; }
Value
CoreDispatcher CoreDispatcher CoreDispatcher

The event dispatcher for the window.

Attributes

FlowDirection FlowDirection FlowDirection FlowDirection

Gets or sets the horizontal origin of the window's reading order alignment. If the language specified by the user interface is right-aligned (such as in Arabic or Hebrew), the horizontal origin of the reading layout for the window is on the right edge.

public CoreWindowFlowDirection FlowDirection { get; set; }public CoreWindowFlowDirection FlowDirection { get; set; }Public ReadWrite Property FlowDirection As CoreWindowFlowDirectionpublic CoreWindowFlowDirection FlowDirection { get; set; }
Value
CoreWindowFlowDirection CoreWindowFlowDirection CoreWindowFlowDirection

The flow direction of the window's reading layout.

Attributes

IsInputEnabled IsInputEnabled IsInputEnabled IsInputEnabled

Gets or sets a value that indicates whether input is enabled for the app.

public bool IsInputEnabled { get; set; }public bool IsInputEnabled { get; set; }Public ReadWrite Property IsInputEnabled As boolpublic bool IsInputEnabled { get; set; }
Value
bool bool bool

True if input is enabled for the app; false if it is disabled.

Attributes

PointerCursor PointerCursor PointerCursor PointerCursor

Gets or sets the cursor used by the app.

public CoreCursor PointerCursor { get; set; }public CoreCursor PointerCursor { get; set; }Public ReadWrite Property PointerCursor As CoreCursorpublic CoreCursor PointerCursor { get; set; }
Value
CoreCursor CoreCursor CoreCursor

The app's cursor.

Attributes

PointerPosition PointerPosition PointerPosition PointerPosition

Gets the client coordinates of the pointer.

public Point PointerPosition { get; set; }public Point PointerPosition { get; set; }Public ReadWrite Property PointerPosition As Pointpublic Point PointerPosition { get; set; }
Value
Point Point Point

The position of the pointer in device-independent pixel (DIP).

Attributes

Remarks

You cannot read the pointer position with this API when the lock screen is present.

Visible Visible Visible Visible

Gets a value that indicates whether the window is visible.

public bool Visible { get; }public bool Visible { get; }Public ReadOnly Property Visible As boolpublic bool Visible { get; }
Value
bool bool bool

True if the window is visible on the screen; false if it is not.

Attributes

Methods

Activate() Activate() Activate() Activate()

Activates the window. This method is called to present the window on the screen.

public void Activate()public void Activate()Public Function Activate() As voidpublic void Activate()
Attributes

Remarks

The window is presented if the app is the foreground window. If the app has more than one window, the activating window is presented when the app is set to the foreground.

Close() Close() Close() Close()

Closes a secondary window and exits the message loop.

public void Close()public void Close()Public Function Close() As voidpublic void Close()
Attributes

Remarks

This method also causes the ProcessEvents operation to exit the event-processing loop.

GetAsyncKeyState(VirtualKey) GetAsyncKeyState(VirtualKey) GetAsyncKeyState(VirtualKey) GetAsyncKeyState(VirtualKey)

Asynchronously retrieves the state of a virtual key.

public CoreVirtualKeyStates GetAsyncKeyState(VirtualKey virtualKey)public CoreVirtualKeyStates GetAsyncKeyState(VirtualKey virtualKey)Public Function GetAsyncKeyState(virtualKey As VirtualKey) As CoreVirtualKeyStatespublic CoreVirtualKeyStates GetAsyncKeyState(VirtualKey virtualKey)
Parameters
virtualKey
VirtualKey VirtualKey VirtualKey

The virtual key for which state is returned.

Returns

The flags indicating the current state of the supplied virtual key when the input event fired.

Note

All keys support the Locked state (not just the standard Caps Lock and Num Lock keys).

Attributes

GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId()

Retrieves the unique ID for the input device that generated this key event.

GetCurrentKeyEventDeviceId is not supported for all input devices.

public string GetCurrentKeyEventDeviceId()public string GetCurrentKeyEventDeviceId()Public Function GetCurrentKeyEventDeviceId() As stringpublic string GetCurrentKeyEventDeviceId()
Returns
string string string

A unique identifier for the input device associated with the key event, or an empty string. The same device can be assigned a different ID each time it is connected.

After a key event is processed, this method returns an empty string.

Attributes

Remarks

Use GetCurrentKeyEventDeviceId to differentiate between devices that can generate key events, such as multiple Xbox controllers. The device id is useful for associating the input device with a specific user account.

To get a valid device ID, this method must be called from your KeyUp and KeyDown event handlers.

GetForCurrentThread() GetForCurrentThread() GetForCurrentThread() GetForCurrentThread()

Gets the CoreWindow instance for the currently active thread.

public static CoreWindow GetForCurrentThread()public static CoreWindow GetForCurrentThread()Public Static Function GetForCurrentThread() As CoreWindowpublic static CoreWindow GetForCurrentThread()
Returns

The CoreWindow for the currently active thread.

Attributes

GetKeyState(VirtualKey) GetKeyState(VirtualKey) GetKeyState(VirtualKey) GetKeyState(VirtualKey)

Retrieves the state of a virtual key.

public CoreVirtualKeyStates GetKeyState(VirtualKey virtualKey)public CoreVirtualKeyStates GetKeyState(VirtualKey virtualKey)Public Function GetKeyState(virtualKey As VirtualKey) As CoreVirtualKeyStatespublic CoreVirtualKeyStates GetKeyState(VirtualKey virtualKey)
Parameters
virtualKey
VirtualKey VirtualKey VirtualKey

The virtual key for which state is returned.

Returns

The flags indicating the current state of the supplied virtual key when the input event fired.

Note

All keys support the Locked state (not just the standard Caps Lock and Num Lock keys).

Attributes

ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture()

Dissociates pointer input from the app, if previously associated through SetPointerCapture, and restores normal pointer input processing.

public void ReleasePointerCapture()public void ReleasePointerCapture()Public Function ReleasePointerCapture() As voidpublic void ReleasePointerCapture()
Attributes

SetPointerCapture() SetPointerCapture() SetPointerCapture() SetPointerCapture()

Associates pointer input with the app. Once a pointer is captured, all subsequent events associated with that pointer are fired by the app.

public void SetPointerCapture()public void SetPointerCapture()Public Function SetPointerCapture() As voidpublic void SetPointerCapture()
Attributes

Remarks

A pointer can be captured only by a single app at any time. Only the foreground window can capture the pointer. Pointer events continue even if the pointer moves outside the bounds of the app.

A pointer can only be captured when contact is detected (mouse button pressed, touch contact down, stylus in contact), and the pointer is within the bounding rectangle of the app.

The pointer is released on a PointerReleased or a PointerCaptureLost event, or ReleasePointerCapture is explicitly called.

Events

Activated Activated Activated Activated

Is fired when the window completes activation or deactivation.

public event TypedEventHandler Activatedpublic event TypedEventHandler ActivatedPublic Event Activatedpublic event TypedEventHandler Activated
Attributes

AutomationProviderRequested AutomationProviderRequested AutomationProviderRequested AutomationProviderRequested

Is fired when a request for an automation handler is generated.

public event TypedEventHandler AutomationProviderRequestedpublic event TypedEventHandler AutomationProviderRequestedPublic Event AutomationProviderRequestedpublic event TypedEventHandler AutomationProviderRequested
Attributes

CharacterReceived CharacterReceived CharacterReceived CharacterReceived

Is fired when a new character is received by the input queue.

public event TypedEventHandler CharacterReceivedpublic event TypedEventHandler CharacterReceivedPublic Event CharacterReceivedpublic event TypedEventHandler CharacterReceived
Attributes

Remarks

Apps do not receive this event when an is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Closed Closed Closed Closed

Is fired when the app terminates.

public event TypedEventHandler Closedpublic event TypedEventHandler ClosedPublic Event Closedpublic event TypedEventHandler Closed
Attributes

Remarks

Note

Apps are typically suspended, not terminated. As a result, this event is rarely fired, if ever.

ClosestInteractiveBoundsRequested ClosestInteractiveBoundsRequested ClosestInteractiveBoundsRequested ClosestInteractiveBoundsRequested

Note

Not intended for general use.

Occurs when a framework input manager requests the bounding rectangle of an interactive element within a specific bounding rectangle and closest to a specific pointer.

public event TypedEventHandler ClosestInteractiveBoundsRequestedpublic event TypedEventHandler ClosestInteractiveBoundsRequestedPublic Event ClosestInteractiveBoundsRequestedpublic event TypedEventHandler ClosestInteractiveBoundsRequested
Attributes

InputEnabled InputEnabled InputEnabled InputEnabled

Occurs when input is enabled or disabled for the app.

public event TypedEventHandler InputEnabledpublic event TypedEventHandler InputEnabledPublic Event InputEnabledpublic event TypedEventHandler InputEnabled
Attributes

KeyDown KeyDown KeyDown KeyDown

Is fired when a non-system key is pressed.

public event TypedEventHandler KeyDownpublic event TypedEventHandler KeyDownPublic Event KeyDownpublic event TypedEventHandler KeyDown
Attributes

Remarks

Apps do not receive this event when an is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

KeyUp KeyUp KeyUp KeyUp

Is fired when a non-system key is released after a press.

public event TypedEventHandler KeyUppublic event TypedEventHandler KeyUpPublic Event KeyUppublic event TypedEventHandler KeyUp
Attributes

Remarks

Apps do not receive this event when an IME is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

PointerCaptureLost PointerCaptureLost PointerCaptureLost PointerCaptureLost

Occurs when a pointer moves to another app. This event is raised after PointerExited and is the final event received by the app for this pointer.

public event TypedEventHandler PointerCaptureLostpublic event TypedEventHandler PointerCaptureLostPublic Event PointerCaptureLostpublic event TypedEventHandler PointerCaptureLost
Attributes

PointerEntered PointerEntered PointerEntered PointerEntered

Occurs when a pointer moves into the bounding box of the app.

public event TypedEventHandler PointerEnteredpublic event TypedEventHandler PointerEnteredPublic Event PointerEnteredpublic event TypedEventHandler PointerEntered
Attributes

Remarks

For touch input, the app receives this event before a PointerPressed event.

PointerExited PointerExited PointerExited PointerExited

Occurs when the pointer moves outside the bounding box of the app.

public event TypedEventHandler PointerExitedpublic event TypedEventHandler PointerExitedPublic Event PointerExitedpublic event TypedEventHandler PointerExited
Attributes

Remarks

For touch input, the app receives this event before a PointerReleased event.

PointerMoved PointerMoved PointerMoved PointerMoved

Occurs when a pointer moves within the bounding box of the app.

public event TypedEventHandler PointerMovedpublic event TypedEventHandler PointerMovedPublic Event PointerMovedpublic event TypedEventHandler PointerMoved
Attributes

PointerPressed PointerPressed PointerPressed PointerPressed

Occurs when a mouse button is clicked, or the digitizer surface has been touched by a finger or pen, within the bounding rectangle of the app.

An interaction session starts when a single contact is detected and ends when that contact, and all subsequent contacts in the same session, are no longer detected.

This event is fired for the first contact detected in the interaction session. Details for all other concurrent contact pointers are exposed through a PointerPointProperties object (obtained by getting the Properties property from a PointerPoint object).

public event TypedEventHandler PointerPressedpublic event TypedEventHandler PointerPressedPublic Event PointerPressedpublic event TypedEventHandler PointerPressed
Attributes

PointerReleased PointerReleased PointerReleased PointerReleased

Occurs when a pressed mouse button is released, or a touch or pen contact is lifted from the digitizer surface, within the bounding rectangle of the app (or outside the bounding rectangle, if the pointer is captured).

public event TypedEventHandler PointerReleasedpublic event TypedEventHandler PointerReleasedPublic Event PointerReleasedpublic event TypedEventHandler PointerReleased
Attributes

Remarks

An interaction session starts when a single contact is detected and ends when that contact, and all subsequent contacts in the same session, are no longer detected.

This event is fired for each contact detected in the interaction session (except for mouse, where this event is fired only when the last mouse button is released).

PointerRoutedAway PointerRoutedAway PointerRoutedAway PointerRoutedAway

Occurs on the process receiving input when the pointer input is routed to another process.

public event TypedEventHandler PointerRoutedAwaypublic event TypedEventHandler PointerRoutedAwayPublic Event PointerRoutedAwaypublic event TypedEventHandler PointerRoutedAway
Attributes

Remarks

This event is not fired on a PointerReleased event.

PointerRoutedReleased PointerRoutedReleased PointerRoutedReleased PointerRoutedReleased

Occurs on a process associated with, but not currently receiving input from, a pointer that fires a PointerReleased event on a different process.

public event TypedEventHandler PointerRoutedReleasedpublic event TypedEventHandler PointerRoutedReleasedPublic Event PointerRoutedReleasedpublic event TypedEventHandler PointerRoutedReleased
Attributes

PointerRoutedTo PointerRoutedTo PointerRoutedTo PointerRoutedTo

Occurs on the process not currently receiving input, but designated to begin receiving input from another process.

public event TypedEventHandler PointerRoutedTopublic event TypedEventHandler PointerRoutedToPublic Event PointerRoutedTopublic event TypedEventHandler PointerRoutedTo
Attributes

Remarks

This event is not fired on a PointerPressed event.

PointerWheelChanged PointerWheelChanged PointerWheelChanged PointerWheelChanged

Occurs when the wheel button is rotated.

public event TypedEventHandler PointerWheelChangedpublic event TypedEventHandler PointerWheelChangedPublic Event PointerWheelChangedpublic event TypedEventHandler PointerWheelChanged
Attributes

ResizeCompleted ResizeCompleted ResizeCompleted ResizeCompleted

Prerelease. Occurs when a user finishes resizing the window.

public event TypedEventHandler ResizeCompletedpublic event TypedEventHandler ResizeCompletedPublic Event ResizeCompletedpublic event TypedEventHandler ResizeCompleted
Attributes

ResizeStarted ResizeStarted ResizeStarted ResizeStarted

Prerelease. Occurs when a user starts to resize the window.

public event TypedEventHandler ResizeStartedpublic event TypedEventHandler ResizeStartedPublic Event ResizeStartedpublic event TypedEventHandler ResizeStarted
Attributes

SizeChanged SizeChanged SizeChanged SizeChanged

Occurs when the window size is changed.

public event TypedEventHandler SizeChangedpublic event TypedEventHandler SizeChangedPublic Event SizeChangedpublic event TypedEventHandler SizeChanged
Attributes

Remarks

The SizeChanged event is exposed to XAML apps as the Window.SizeChanged event and to HTML apps as the window.resize event.

This event occurs when the window size changes or when one of the following properties changes:

TouchHitTesting TouchHitTesting TouchHitTesting TouchHitTesting

Occurs when a touch contact area intersects the bounding rectangle (or polygon) of a window that is registered for touch hit testing.

public event TypedEventHandler TouchHitTestingpublic event TypedEventHandler TouchHitTestingPublic Event TouchHitTestingpublic event TypedEventHandler TouchHitTesting
Attributes

VisibilityChanged VisibilityChanged VisibilityChanged VisibilityChanged

Is fired when the window visibility is changed.

public event TypedEventHandler VisibilityChangedpublic event TypedEventHandler VisibilityChangedPublic Event VisibilityChangedpublic event TypedEventHandler VisibilityChanged
Attributes