CoreInputView.XYFocusTransferringFromPrimaryView 事件

定义

在输入窗格失去焦点之前和 UI 元素获得焦点之前发生。

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

事件类型

Windows 要求

设备系列
Windows 10, version 1803 (在 10.0.17134.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v6.0 中引入)

示例

此处,我们演示如何处理 XYFocusTransferringFromPrimaryView 事件,并确定应在应用程序中接收焦点的 UI 元素。 焦点候选项根据相对于最后一个输入窗格子元素的边界矩形的位置进行区分。

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

注解

主视图是指 CoreInputViewKind.KeyboardCoreInputViewKind.Handwriting 视图之一,而 CoreInputView 可以是 CoreInputViewKind 中的任何值。

从输入窗格导航到应用程序中的 UI 元素时指定焦点目标。

适用于

另请参阅