Trigger.Value 属性

定义

获取或设置要与元素的属性值进行比较的值。Gets or sets the value to be compared with the property value of the element. 该比较是一项引用相等性检查。The comparison is a reference equality check.

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Markup.SetterTriggerConditionValueConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.DependsOn("Property")]
[System.Windows.Markup.DependsOn("SourceName")]
public object Value { get; set; }
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.DependsOn("Property")]
[System.Windows.Markup.DependsOn("SourceName")]
public object Value { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Markup.SetterTriggerConditionValueConverter))>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DependsOn("Property")>]
[<System.Windows.Markup.DependsOn("SourceName")>]
member this.Value : obj with get, set
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DependsOn("Property")>]
[<System.Windows.Markup.DependsOn("SourceName")>]
member this.Value : obj with get, set
Public Property Value As Object

属性值

Object

默认值是 nullThe default value is null. 请参见“异常”部分。See also the Exceptions section.

属性

例外

不支持诸如绑定之类的表达式。Expressions such as bindings are not supported.

使用 Trigger 之后,就不能再对其进行修改。After a Trigger is in use, it cannot be modified.

示例

下面的示例在 Foreground 属性为时更改按钮的属性 IsPressed trueThe following example changes the Foreground property of a button when the IsPressed property is true.

<Style x:Key="Triggers" TargetType="Button">
    <Style.Triggers>
    <Trigger Property="IsPressed" Value="true">
        <Setter Property = "Foreground" Value="Green"/>
    </Trigger>
    </Style.Triggers>
</Style>

注解

此值与的属性所返回的属性值进行比较 Property TriggerThis value is compared with the property value returned by the Property property of the Trigger. 执行的比较是引用质量检查。The comparison that is performed is a reference quality check. 如果两个值相等,则关联的 Setter 将应用指定的属性值。If the two values are equal, then the associated Setters apply the specified property values.

请注意,必须 Property 在上指定和 Value 属性,这样 Trigger 触发器才有意义。Note that you must specify both the Property and Value properties on a Trigger for the trigger to be meaningful. 因此,如果未指定一个或两个属性,则会引发异常。Therefore, if one or both of the properties are not specified, then an exception is thrown.

XAML 属性元素用法XAML Property Element Usage

<object>  
  <object.Value>  
    Value  
  </object.Value>  
</object>  

适用于

另请参阅