通过


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

属性值

将应用到的 Value ADependencyProperty。 默认值为 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>

注解

请注意,必须同时指定Property或引发异常的SetterValue属性。

适用于

另请参阅