Focusable Property

UIElement.Focusable Property


Gets or sets a value that indicates whether the element can receive focus. This is a .GTMT

Namespace:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

public bool Focusable { get; set; }

Property Value

Type: System.Boolean

true if the element is focusable; otherwise false. The default is false, but see Remarks.

Only the focused element receives keyboard input.

Focusable is the Microsoft .NET property accessor for what is in reality a . This particular quite frequently has its apparent "default" value set differently in derived element classes, particularly in controls. This commonly occurs in one of two ways:GTMTGTMT

  • The is inherited by a particular derived class, but that derived class overrides the metadata of the and changes the property default value.GTMTGTMT

  • A style or template is applied to an element, which sets that value differently.GTMT

For example, the apparent "default" of Focusable for a Button control will be true, even though Button inherits Focusable as a common language runtime (CLR) property directly from UIElement. This is because the applied metadata value for the Focusable  was overridden within the static constructor of the Control base class, which is situated between Button and UIElement in the class hierarchy.GTMT

When inherited by Control or its derived classes, Control redefines the default value of this property to be true.

When inherited by Label (which is a Control derived class), the default value is again redefined to be false.

Identifier field


Metadata properties set to true


Notes to Inheritors:

When deriving from UIElement directly (as opposed to from Control), consider whether you wish your element to be focusable, because by default the element will not be focusable. If you wish your element to be focusable, override the metadata for this property within your type's static constructor as follows:

Code snippet is not found. Confirm that the code snippet name 'CorePseudocode' is correct.

where myElement should be the class name of the type that you are overriding the metadata value on.

Legacy Code Example

The following example code illustrates a control template for a particular custom control, which sets Focusable false on one of the elements within the template.

Code snippet is not found. Confirm that the code snippet name 'RichTextBox_NoScrollViewer' is correct.

.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft