Trigger Trigger Trigger Trigger Class

定义

表示一个触发器,它按条件应用属性值或执行操作。Represents a trigger that applies property values or performs actions conditionally.

public ref class Trigger : System::Windows::TriggerBase, System::ComponentModel::ISupportInitialize, System::Windows::Markup::IAddChild
[System.Windows.Markup.ContentProperty("Setters")]
[System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")]
public class Trigger : System.Windows.TriggerBase, System.ComponentModel.ISupportInitialize, System.Windows.Markup.IAddChild
type Trigger = class
    inherit TriggerBase
    interface IAddChild
    interface ISupportInitialize
Public Class Trigger
Inherits TriggerBase
Implements IAddChild, ISupportInitialize
继承
属性
实现

示例

下面的示例演示了一个Style名为Button的可用于控件的。The following example shows a named Style available to Button controls. true Foreground定义一个Trigger元素, 该元素在IsPressed属性为时更改按钮的属性。 StyleThe Style defines a Trigger element that 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>

注解

WPFWPF定义对应于最终用户操作IsMouseOver的属性, 例如当用户将光标UIElement悬停在上时true设置为的属性或的相应IsMouseOver属性ContentElementdefines properties that correspond to end-user actions, such as the IsMouseOver property that is set to true when the user hovers the cursor over a UIElement or the corresponding IsMouseOver property of a ContentElement. 表示属性值和元素中的最终用户操作, 允许Trigger WPFWPF样式基于这些最终用户操作更改属性值, 所有这些操作都是从标记中进行的。Representing end-user actions in property values, along with the Trigger element, allows WPFWPF styles to change property values based on those end-user actions, all from within markup.

当不再满足触发条件时, 触发器更改的属性将自动重置为其以前的值。The properties changed by triggers are automatically reset to their previous value when the triggered condition is no longer satisfied. 触发器针对暂时性状态进行了优化, 这些状态应更改并返回到原始状态, 如IsPressed打开ButtonIsSelected打开ListBoxItemTriggers are optimized for transient states which are expected to change and return to original state, such as IsPressed on Button and IsSelected on ListBoxItem. Property相关的必须是依赖项属性。The Property of interest must be a dependency property.

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

对象的Setters属性只能包含对象。Setter TriggerThe Setters property of a Trigger object can only consist of Setter objects. 将子对象添加到对象Trigger会将该子级隐式添加到对象的SetterBaseCollectionSetter TriggerAdding a Setter child to a Trigger object implicitly adds it to the SetterBaseCollection for the Trigger object. EventSetter对象不受支持;仅Style.Setters 支持EventSetter对象。EventSetter objects are not supported; only Style.Setters supports EventSetter objects.

还有其他类型的触发器。There are other types of triggers. MultiTrigger允许你根据多个属性的状态应用更改。MultiTrigger allows you to apply changes based on the state of multiple properties. EventTrigger允许你在事件发生时应用更改。EventTrigger allows you to apply changes when an event occurs. DataTriggerMultiDataTrigger用于数据绑定属性。DataTrigger and MultiDataTrigger are for data-bound properties.

构造函数

Trigger() Trigger() Trigger() Trigger()

初始化 Trigger 类的新实例。Initializes a new instance of the Trigger class.

属性

DependencyObjectType DependencyObjectType DependencyObjectType DependencyObjectType

获取对此实例的 CLRCLR 类型进行包装的 DependencyObjectTypeGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(Inherited from DependencyObject)
Dispatcher Dispatcher Dispatcher Dispatcher

获取与此 Dispatcher 关联的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
EnterActions EnterActions EnterActions EnterActions

获取要在触发器对象变为活动状态时应用的 TriggerAction 对象的集合。Gets a collection of TriggerAction objects to apply when the trigger object becomes active. 此属性不适用于 EventTrigger 类。This property does not apply to the EventTrigger class.

(Inherited from TriggerBase)
ExitActions ExitActions ExitActions ExitActions

获取要在触发器对象变为非活动状态时应用的 TriggerAction 对象的集合。Gets a collection of TriggerAction objects to apply when the trigger object becomes inactive. 此属性不适用于 EventTrigger 类。This property does not apply to the EventTrigger class.

(Inherited from TriggerBase)
IsSealed IsSealed IsSealed IsSealed

获取一个值,该值指示此实例当前是否为密封的(只读)。Gets a value that indicates whether this instance is currently sealed (read-only).

(Inherited from DependencyObject)
Property Property Property Property

获取或设置一个属性,该属性返回要与触发器的 Value 属性进行比较的值。Gets or sets the property that returns the value that is compared with the Value property of the trigger. 该比较是一项引用相等性检查。The comparison is a reference equality check.

Setters Setters Setters Setters

获取 Setter 对象的集合,这些对象描述当满足指定条件时要应用的属性值。Gets a collection of Setter objects, which describe the property values to apply when the specified condition has been met.

SourceName SourceName SourceName SourceName

获取或设置对象的名称,该对象具有可应用关联的 setter 的属性。Gets or sets the name of the object with the property that causes the associated setters to be applied.

Value Value Value Value

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

方法

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

确定调用线程是否可以访问此 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

清除属性的本地值。Clears the local value of a property. 要清除的属性由 DependencyProperty 标识符指定。The property to be cleared is specified by a DependencyProperty identifier.

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

清除只读属性的本地值。Clears the local value of a read-only property. 要清除的属性由 DependencyPropertyKey 指定。The property to be cleared is specified by a DependencyPropertyKey.

(Inherited from DependencyObject)
CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty)

对指定依赖属性的值进行强制。Coerces the value of the specified dependency property. 通过对调用方 DependencyObject 上存在的依赖属性的属性元数据中所指定的任何 CoerceValueCallback 函数进行调用来完成此操作。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(Inherited from DependencyObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObjectDetermines whether a provided DependencyObject is equivalent to the current DependencyObject.

(Inherited from DependencyObject)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

获取此 DependencyObject 的哈希代码。Gets a hash code for this DependencyObject.

(Inherited from DependencyObject)
GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator()

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(Inherited from DependencyObject)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

DependencyObject 的此实例返回依赖属性的当前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty)

重新计算指定依赖项属性的有效值Re-evaluates the effective value for the specified dependency property

(Inherited from DependencyObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs)

每当更新此 DependencyObject 的任何依赖属性的有效值时调用。Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. 更改的特定依赖项属性将在事件数据中报告。The specific dependency property that changed is reported in the event data.

(Inherited from DependencyObject)
ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

如果存在,则返回依赖属性的本地值。Returns the local value of a dependency property, if it exists.

(Inherited from DependencyObject)
ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs)

处理类型转换器为 Trigger 对象的属性提供值的情况。Handles cases where a type converter provides a value for a property of a Trigger object.

SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object)

设置依赖属性的值而不更改其值源。Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object)

设置依赖属性的本地值,该值由其依赖属性标识符指定。Sets the local value of a dependency property, specified by its dependency property identifier.

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object)

设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(Inherited from DependencyObject)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

显式界面实现

IAddChild.AddChild(Object) IAddChild.AddChild(Object) IAddChild.AddChild(Object) IAddChild.AddChild(Object)

添加子对象。Adds a child object.

IAddChild.AddText(String) IAddChild.AddText(String) IAddChild.AddText(String) IAddChild.AddText(String)

将节点的文本内容添加到对象。Adds the text content of a node to the object.

ISupportInitialize.BeginInit() ISupportInitialize.BeginInit() ISupportInitialize.BeginInit() ISupportInitialize.BeginInit()

用信号通知对象初始化即将开始。Signals the object that initialization is starting.

ISupportInitialize.EndInit() ISupportInitialize.EndInit() ISupportInitialize.EndInit() ISupportInitialize.EndInit()

用信号通知对象初始化已完成。Signals the object that initialization is complete.

适用于

另请参阅