CoreInputView.XYFocusTransferringFromPrimaryView 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生在輸入窗格失去焦點之前,以及 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.Keyboard 或 CoreInputViewKind.Handwriting 檢視,而 CoreInputView 可以是 CoreInputViewKind的任何值。
從輸入窗格巡覽至應用程式中的 UI 元素時,指定焦點目標。