InputFocusController.TrySetFocus Method

Definition

Attempts to set focus to the ContentIsland associated with the InputFocusController.

public:
 virtual bool TrySetFocus() = TrySetFocus;
bool TrySetFocus();
public bool TrySetFocus();
function trySetFocus()
Public Function TrySetFocus () As Boolean

Returns

Boolean

bool

True, if focus was set successfully; otherwise, false.

Examples

The following example shows how to indicate focus is on a TextBox within a ContentIsland based on pointer input.

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

Remarks

Due to other message processing requirements, focus might move from the ContentIsland by the time this request is processed.

A user might also move focus before this request is processed.

Processing this request can raise GotFocus and LostFocus events in quick succession.

Applies to