Redigera

Dela via


ContentElement.Focusable Property

Definition

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

public:
 property bool Focusable { bool get(); void set(bool value); };
public bool Focusable { get; set; }
member this.Focusable : bool with get, set
Public Property Focusable As Boolean

Property Value

true if the element is focusable; otherwise false. The default is false.

Implements

Examples

The following example creates a style that makes a Paragraph focusable by default and gives it a visual behavior when it receives focus.

<Style x:Key="FocusableParagraph" TargetType="{x:Type Paragraph}">
  <Setter Property="Focusable" Value="true"/>
  <Style.Triggers>
    <Trigger Property="IsFocused" Value="True">
      <Setter Property = "Background" Value="{StaticResource BlueGreenBrush}"/>
    </Trigger>
  </Style.Triggers>
</Style>

Remarks

Only the focused element receives keyboard input.

Certain derived classes might override metadata for this dependency property such that the derived class is focusable by default.

When inherited by Hyperlink or its derived classes, Hyperlink overrides the metadata for this dependency property and redefines the default value of this property to be true.

Dependency property information

Identifier field FocusableProperty
Metadata properties set to true None

Notes to inheritors

When you derive from ContentElement, consider whether you want your element to be focusable, because by default it will not be focusable. If you want your element to be focusable, override the metadata for this property in your derived class static constructor as follows:

FocusableProperty.OverrideMetadata(typeof(myElement), new UIPropertyMetadata(true));
FocusableProperty.OverrideMetadata(GetType(myElement), New UIPropertyMetadata(True))

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

Applies to

See also