ContentElement.Focusable 屬性

定義

取得或設定元素是否能夠接收焦點的值。

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

屬性值

如果這個項目可設定焦點,則為 true;否則為 false。 預設為 false

實作

範例

下列範例會建立一個樣式,預設會 Paragraph 讓焦點成為可設定焦點,並在收到焦點時提供視覺行為。

<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>

備註

只有焦點元素會接收鍵盤輸入。

某些衍生類別可能會覆寫此相依性屬性的中繼資料,讓衍生類別預設為可焦點。

繼承自 Hyperlink 或其衍生類別時, Hyperlink 覆寫此相依性屬性的中繼資料,並將此屬性的預設值重新定義為 true

相依性屬性資訊

識別碼欄位 FocusableProperty
設定為 的中繼資料屬性 true

繼承者的注意事項

當您衍生自 ContentElement 時,請考慮是否要讓元素成為可焦點,因為預設不會將它設為焦點。 如果您想要讓元素成為可焦點,請覆寫衍生類別靜態建構函式中此屬性的中繼資料,如下所示:

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

其中 myElement 是您要覆寫中繼資料值的型別類別名稱。

適用於

另請參閱