Setter.Property 屬性

定義

取得或設定將套用 Value 的屬性。

public:
 property System::Windows::DependencyProperty ^ Property { System::Windows::DependencyProperty ^ get(); void set(System::Windows::DependencyProperty ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Modifiability=System.Windows.Modifiability.Unmodifiable, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.Ambient]
public System.Windows.DependencyProperty Property { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Modifiability=System.Windows.Modifiability.Unmodifiable, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.Ambient>]
member this.Property : System.Windows.DependencyProperty with get, set
Public Property Property As DependencyProperty

屬性值

DependencyProperty

將套用 DependencyPropertyValue。 預設值為 null。

屬性

例外狀況

Property 屬性不能是 null

指定的 Property 屬性不可以是唯讀。

如果指定的 Value 對於指定的 Property 之型別無效。

範例

下列範例會定義將套用至每個 TextBlock 專案的樣式。

<Style TargetType="{x:Type TextBlock}">
  <Setter Property="FontFamily" Value="Segoe Black" />
  <Setter Property="HorizontalAlignment" Value="Center" />
  <Setter Property="FontSize" Value="12pt" />
  <Setter Property="Foreground" Value="#777777" />
</Style>

下列範例顯示會影響 Background 之 屬性的 Control 樣式宣告。 請注意,此範例中的屬性名稱與類別名稱 () Control 限定,因為 Style 未指定 TargetType

<Style x:Key="Style1">
  <Setter Property="Control.Background" Value="Yellow"/>
</Style>

備註

請注意,您必須同時在 或 上 Setter 指定 PropertyValue 屬性,否則會擲回例外狀況。

適用於

另請參閱