ContentElement.Focusable ContentElement.Focusable ContentElement.Focusable ContentElement.Focusable Property


取得或設定元素是否能夠接收焦點的值。Gets or sets a value that indicates whether the element can receive focus.

 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


如果這個項目可設定焦點,則為 true;否則為 falsetrue if the element is focusable; otherwise false. 預設為 falseThe default is false.



下列範例會建立樣式,Paragraph可焦點化預設情況下並為其提供視覺化行為,收到焦點時。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"/>
    <Trigger Property="IsFocused" Value="True">
      <Setter Property = "Background" Value="{StaticResource BlueGreenBrush}"/>


只有具有焦點的項目收到鍵盤輸入。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.

當繼承Hyperlink或其衍生的類別,Hyperlink覆寫這個相依性屬性的中繼資料,並會重新定義預設值,這個屬性是trueWhen 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
若要設定的中繼資料屬性 trueMetadata properties set to true None

繼承者注意事項Notes to inheritors

當您衍生自ContentElement,請考慮是否要讓您是可設定焦點,因為依預設它不是可設定焦點的項目。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))

其中myElement是類別名稱,您會在覆寫中繼資料值的類型。where myElement is the class name of the type that you are overriding the metadata value on.