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

定義

取得或設定元素是否能夠接收焦點的值。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

屬性值

如果這個項目為可設定焦點,則為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"/>
  <Style.Triggers>
    <Trigger Property="IsFocused" Value="True">
      <Setter Property = "Background" Value="{StaticResource BlueGreenBrush}"/>
    </Trigger>
  </Style.Triggers>
</Style>

備註

只有焦點的元素會接收鍵盤輸入。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 , 會覆寫這個相依性屬性的中繼資料, 並將true這個屬性的預設值重新定義為。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
中繼資料屬性設定為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.

適用於

另請參閱