Share via


CoreInputView.XYFocusTransferringFromPrimaryView Event

Definition

Occurs before the input pane loses focus and before a UI element gets focus.

// Register
event_token XYFocusTransferringFromPrimaryView(TypedEventHandler<CoreInputView, CoreInputViewTransferringXYFocusEventArgs const&> const& handler) const;

// Revoke with event_token
void XYFocusTransferringFromPrimaryView(event_token const* cookie) const;

// Revoke with event_revoker
CoreInputView::XYFocusTransferringFromPrimaryView_revoker XYFocusTransferringFromPrimaryView(auto_revoke_t, TypedEventHandler<CoreInputView, CoreInputViewTransferringXYFocusEventArgs const&> const& handler) const;
public event TypedEventHandler<CoreInputView,CoreInputViewTransferringXYFocusEventArgs> XYFocusTransferringFromPrimaryView;
function onXYFocusTransferringFromPrimaryView(eventArgs) { /* Your code */ }
coreInputView.addEventListener("xyfocustransferringfromprimaryview", onXYFocusTransferringFromPrimaryView);
coreInputView.removeEventListener("xyfocustransferringfromprimaryview", onXYFocusTransferringFromPrimaryView);
- or -
coreInputView.onxyfocustransferringfromprimaryview = onXYFocusTransferringFromPrimaryView;
Public Custom Event XYFocusTransferringFromPrimaryView As TypedEventHandler(Of CoreInputView, CoreInputViewTransferringXYFocusEventArgs) 

Event Type

Windows requirements

Device family
Windows 10, version 1803 (introduced in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v6.0)

Examples

Here, we show how to handle the XYFocusTransferringFromPrimaryView event and identify which UI element should receive focus in the application. The focus candidates are differentiated based on location relative to the bounding rect of the last input pane child element.

private void OnXYFocusTransferringFromPrimaryView(CoreInputView sender,
CoreInputViewTransferringXYFocusEventArgs args)
{
    bool acceptXYFocusTransfer = false;

    switch (args.Direction)
    {
        case CoreInputViewXYFocusTransferDirection.Down:
            // If focus navigation is moving down,
            // set focus to the top element (usernameTextBox).
            this.usernameTextBox.Focus(FocusState.Programmatic);
            acceptXYFocusTransfer = true;
            break;

        case CoreInputViewXYFocusTransferDirection.Up:
            // If focus navigation is moving up,
            // there are two focus candidates.
            // Check the Origin rect to determine the more
            // suitable candidate.
            if ((args.Origin.X + (args.Origin.Width / 2.0)) <
            Window.Current.Bounds.Width / 2.0)
            {
            this.cancelButton.Focus(FocusState.Programmatic);
            }
            else
            {
            this.submitButton.Focus(FocusState.Programmatic);
            }
            acceptXYFocusTransfer = true;
            break;

        case CoreInputViewXYFocusTransferDirection.Left:
        case CoreInputViewXYFocusTransferDirection.Right:
            // If focus navigation is moving left or right,
            // maintain focus on the currently focused UI element.
            acceptXYFocusTransfer = true;
            break;

        default:
            // Don't accept XY focus movement.
            break;
    }

    if (acceptXYFocusTransfer)
    {
        args.TransferHandled = true;
        this.KeyDown += OnMainPageKeyDown;
    }
}

Remarks

Primary view refers to either of the CoreInputViewKind.Keyboard or CoreInputViewKind.Handwriting views, while CoreInputView can be any of the values from CoreInputViewKind.

Designate the focus target when navigating from the input pane to a UI element in your application.

Applies to

See also