Udostępnij za pośrednictwem


UIElement.FocusState Property

Definition

Gets a value that specifies whether this control has focus, and the mode by which focus was obtained.

public:
 property FocusState FocusState { FocusState get(); };
FocusState FocusState();
public FocusState FocusState { get; }
var focusState = uIElement.focusState;
Public ReadOnly Property FocusState As FocusState

Property Value

A value of the enumeration. A value of Unfocused indicates that the control does not have focus.

Remarks

This property supports controls that use different visual styles depending on whether the control was focused by the keyboard or by other means. Some controls use visual states that show a visible focus indicator if the control was focused by a keyboard action, but do not show the indicator if the control was focused by a pointer action. The internal logic of such a control implements OnGotFocus and then gets the value of FocusState from the sender. If FocusState is Keyboard, then a different named visual state that includes a focus rectangle is loaded, by calling GoToState. Typically, focus-related visual states are grouped together in the default control template XAML. Custom controls that want to use different focus visuals depending on the means of focus can implement this same logic themselves. See OnGotFocus.

Another way to use this property is to use FocusManager to determine which element in the overall UI has focus, and then call this method on that element to get information on how the control received focus.

Applies to