InputFocusController.TrySetFocus 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
嘗試將焦點設定為與 InputFocusController 相關的 ContentIsland 。
public:
virtual bool TrySetFocus() = TrySetFocus;
bool TrySetFocus();
public bool TrySetFocus();
function trySetFocus()
Public Function TrySetFocus () As Boolean
傳回
Boolean
bool
沒錯,如果焦點設定成功;否則,則為錯誤。
範例
以下範例說明如何根據指標輸入,在 ContentIsland 中表示焦點放在 TextBox 上。
void OnClick(PointerPoint clickLocation)
{
if (IsWithinBoundsOfTextBox(clickLocation))
{
InputFocusController focusController = InputFocusController.GetForIsland(myIsland);
if (!focusController.HasFocus())
{
bool nowHasFocus = focusController.TrySetFocus();
// Change styling of text box based on whether the Island received focus
if (nowHasFocus)
{
DrawTextBoxBorder();
}
else
{
RemoveTextBoxBorder();
}
}
}
}
備註
由於其他訊息處理需求,當此請求處理時,焦點可能會從 ContentIsland 轉移。
使用者也可能在此請求處理前移動焦點。
處理此請求時,可能會迅速觸發 GotFocus 與 LostFocus 事件。