InputFocusController.TrySetFocus Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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.