EventTrigger 类

定义

表示一个触发器,该触发器应用一组操作以响应一个事件。Represents a trigger that applies a set of actions in response to an event.

public ref class EventTrigger : System::Windows::TriggerBase, System::Windows::Markup::IAddChild
[System.Windows.Markup.ContentProperty("Actions")]
public class EventTrigger : System.Windows.TriggerBase, System.Windows.Markup.IAddChild
type EventTrigger = class
    inherit TriggerBase
    interface IAddChild
Public Class EventTrigger
Inherits TriggerBase
Implements IAddChild
继承
属性
实现

示例

此示例演示如何在样式中使用事件触发器来对的MouseEnterMouseLeave事件FrameworkElement进行动画处理。This example shows how to use event triggers in a style to animate the MouseEnter and MouseLeave events of a FrameworkElement. 在此示例中, Style TargetType将设置为RectangleIn this example, the Style has the TargetType set to Rectangle. 因此, 不需要用类名来限定MouseEnterMouseLeave事件名称。Therefore, there is no need to qualify the MouseEnter and MouseLeave event names with the class name.

<Style TargetType="Rectangle">
  <Setter Property="Width" Value="50" />
  <Setter Property="Height" Value="50" />
  <Setter Property="Margin" Value="20" />
  <Setter Property="HorizontalAlignment" Value="Left" />
  <Style.Triggers>
    <EventTrigger RoutedEvent="MouseEnter">
        <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation To="300" Duration="0:0:1.5" 
                AccelerationRatio="0.10" DecelerationRatio="0.25" 
                Storyboard.TargetProperty="(Canvas.Width)" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
    <EventTrigger RoutedEvent="MouseLeave">
        <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation Duration="0:0:1.5" 
                AccelerationRatio="0.10" DecelerationRatio="0.25" 
                Storyboard.TargetProperty="(Canvas.Width)" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
  </Style.Triggers>
</Style>

注解

TriggerSetters对象具有ActionsEnterActionsExitActions属性, 这些属性基于特定属性的状态应用更改或操作, 而EventTrigger对象在指定的路由事件发生时启动一组。Trigger objects have the Setters, EnterActions, and ExitActions properties that apply changes or actions based on the state of certain properties, while EventTrigger objects start a set of Actions when a specified routed event occurs. 例如, 当鼠标指针位于特定EventTrigger 用户界面 (UI)user interface (UI)控件上时, 可能需要使用来启动一组动画。For example, you may want to use an EventTrigger to start a set of animations when the mouse pointer is over a certain 用户界面 (UI)user interface (UI) control. Trigger不同EventTrigger的是, 没有状态终止的概念, 因此, 一旦引发事件的条件不再为 true, 该操作将不会撤消。Unlike Trigger, EventTrigger has no concept of termination of state, so the action will not be undone once the condition that raised the event is no longer true.

请注意EventTrigger, 使用时, 需要选择不会影响控件固有行为的事件。Note that when using an EventTrigger, you need to choose events that do not interfere with the inherent behavior of your control. 控件 ( Button例如或TextBox ) 对用户输入事件执行特定操作, 例如鼠标单击和键盘事件。Controls such as Button or TextBox perform specific actions on user input events such as mouse clicks and keyboard events. 例如, 如果对按钮进行样式设置MouseDown并尝试将事件设置RoutedEvent为的EventTrigger, 则EventTrigger永远不会应用, 因为该事件首先由按钮处理。For example, if you are styling a button and try to set the MouseDown event as the RoutedEvent of an EventTrigger, the EventTrigger never gets applied because the event first gets handled by the button. 您可以改为PreviewMouseDown使用事件或其他事件。Instead, you can use the PreviewMouseDown event or a different event.

使用数据绑定时, 如果TargetUpdated使用的是事件, 则必须将Binding对象trueNotifyOnTargetUpdated值设置为, 以便引发事件。When using data binding, if you are using the TargetUpdated event, you must set the NotifyOnTargetUpdated value of your Binding object to true for the event to be raised.

如果将EventTrigger EventTrigger子对象添加到对象中, 则会将其隐式添加到对象的TriggerActionCollectionTriggerActionAdding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object.

构造函数

EventTrigger()

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

EventTrigger(RoutedEvent)

使用指定的事件初始化 EventTrigger 类的新实例。Initializes a new instance of the EventTrigger class with the specified event.

属性

Actions

获取事件发生时要应用的操作的集合。Gets the collection of actions to apply when the event occurs.

DependencyObjectType

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

(继承自 DependencyObject)
Dispatcher

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

(继承自 DispatcherObject)
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.

(继承自 TriggerBase)
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.

(继承自 TriggerBase)
IsSealed

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

(继承自 DependencyObject)
RoutedEvent

获取或设置将激活该触发器的 RoutedEventGets or sets the RoutedEvent that will activate this trigger.

SourceName

获取或设置对象的名称,该对象具有激活此触发器的事件。Gets or sets the name of the object with the event that activates this trigger. 仅元素触发器或模板触发器可使用此名称。This is only used by element triggers or template triggers.

方法

AddChild(Object)

将指定的对象添加到当前事件触发器的 Actions 集合中。Adds the specified object to the Actions collection of the current event trigger.

AddText(String)

此方法不受支持并导致异常。This method is not supported and results in an exception.

CheckAccess()

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

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

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

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

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

(继承自 DependencyObject)
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.

(继承自 DependencyObject)
Equals(Object)

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

(继承自 DependencyObject)
GetHashCode()

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

(继承自 DependencyObject)
GetLocalValueEnumerator()

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

(继承自 DependencyObject)
GetType()

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

(继承自 Object)
GetValue(DependencyProperty)

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

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。Re-evaluates the effective value for the specified dependency property.

(继承自 DependencyObject)
MemberwiseClone()

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

(继承自 Object)
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.

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

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

(继承自 DependencyObject)
SetCurrentValue(DependencyProperty, Object)

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

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

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

(继承自 DependencyObject)
SetValue(DependencyPropertyKey, Object)

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

(继承自 DependencyObject)
ShouldSerializeActions()

返回序列化进程是否应序列化此类的实例上 Actions 属性的有效值。Returns whether serialization processes should serialize the effective value of the Actions property on instances of this class.

ShouldSerializeProperty(DependencyProperty)

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

(继承自 DependencyObject)
ToString()

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

(继承自 Object)
VerifyAccess()

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

(继承自 DispatcherObject)

显式界面实现

IAddChild.AddChild(Object)

添加子对象。Adds a child object.

IAddChild.AddText(String)

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

适用于

另请参阅