Setter.Property 屬性

定義

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

C#
[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; }

屬性值

DependencyProperty

將套用 DependencyPropertyValue。 預設值為 null。

屬性

例外狀況

Property 屬性不能是 null

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

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

範例

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

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

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

備註

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

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱