Share via


VisualElement.IsFocused Property

Definition

Gets a value indicating whether this element is focused currently. This is a bindable property.

public bool IsFocused { get; }
member this.IsFocused : bool

Property Value

System.Boolean

true if the element is focused; otherwise, false.

Remarks

Applications may have multiple focuses depending on the implementation of the underlying toolkit. Menus and modals in particular may leave multiple items with focus.

The following example shows conditionally setting a background color based on the focus state.

void UpdateBackground ()
{
  if (myElement.IsFocused)
    myElement.BackgroundColor = Color.Red;
  else
    myElement.BackgroundColor = Color.Blue;
}

Applies to