Xamarin.Forms Guides | Samples

Xamarin.Forms.VisualElement.IsFocused Property

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

Syntax

public Boolean IsFocused { get; }

Value

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.

C# Example

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

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0