Skip to main content
.NET Framework Class Library
EventTrigger Class

Represents a trigger that applies a set of actions in response to an event.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax
<[%$TOPIC/ms602400_en-us_VS_110_2_0_0_0_0%]("Actions")> _
Public Class EventTrigger _
	Inherits [%$TOPIC/ms602400_en-us_VS_110_2_0_0_0_1%] _
	Implements [%$TOPIC/ms602400_en-us_VS_110_2_0_0_0_2%]
[[%$TOPIC/ms602400_en-us_VS_110_2_0_1_0_0%]("Actions")]
public class EventTrigger : [%$TOPIC/ms602400_en-us_VS_110_2_0_1_0_1%], 
	[%$TOPIC/ms602400_en-us_VS_110_2_0_1_0_2%]
[[%$TOPIC/ms602400_en-us_VS_110_2_0_2_0_0%](L"Actions")]
public ref class EventTrigger : public [%$TOPIC/ms602400_en-us_VS_110_2_0_2_0_1%], 
	[%$TOPIC/ms602400_en-us_VS_110_2_0_2_0_2%]
[<[%$TOPIC/ms602400_en-us_VS_110_2_0_3_0_0%]("Actions")>]
type EventTrigger =  
    class 
        inherit [%$TOPIC/ms602400_en-us_VS_110_2_0_3_0_1%] 
        interface [%$TOPIC/ms602400_en-us_VS_110_2_0_3_0_2%] 
    end
public class EventTrigger extends [%$TOPIC/ms602400_en-us_VS_110_2_0_4_0_0%] implements [%$TOPIC/ms602400_en-us_VS_110_2_0_4_0_1%]
<EventTrigger>
  [%$TOPIC/ms602400_en-us_VS_110_2_0_5_0_0%]
</EventTrigger>

The EventTrigger type exposes the following members.

Constructors
  NameDescription
Public method EventTriggerInitializes a new instance of the EventTrigger class.
Public method EventTrigger(RoutedEvent)Initializes a new instance of the EventTrigger class with the specified event.
Top
Properties
  NameDescription
Public property ActionsGets the collection of actions to apply when the event occurs.
Public property DependencyObjectTypeGets the DependencyObjectType that wraps the CLR type of this instance.  (Inherited from DependencyObject.)
Public property DispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public property EnterActionsGets a collection of TriggerAction objects to apply when the trigger object becomes active. This property does not apply to the EventTrigger class. (Inherited from TriggerBase.)
Public property ExitActionsGets a collection of TriggerAction objects to apply when the trigger object becomes inactive. This property does not apply to the EventTrigger class. (Inherited from TriggerBase.)
Public property IsSealedGets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.)
Public property RoutedEventGets or sets the RoutedEvent that will activate this trigger.
Public property SourceNameGets or sets the name of the object with the event that activates this trigger. This is only used by element triggers or template triggers.
Top
Methods
  NameDescription
Protected method AddChildAdds the specified object to the Actions collection of the current event trigger.
Protected method AddTextThis method is not supported and results in an exception.
Public method CheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public method ClearValue(DependencyProperty)Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)
Public method ClearValue(DependencyPropertyKey)Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)
Public method CoerceValueCoerces the value of the specified dependency property. 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.)
Public method EqualsDetermines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeGets a hash code for this DependencyObject. (Inherited from DependencyObject.)
Public method GetLocalValueEnumeratorCreates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method GetValueReturns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)
Public method InvalidatePropertyRe-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnPropertyChangedInvoked 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.)
Public method ReadLocalValueReturns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)
Public method SetCurrentValueSets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)
Public method SetValue(DependencyProperty, Object)Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)
Public method SetValue(DependencyPropertyKey, Object)Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)
Public method ShouldSerializeActionsReturns whether serialization processes should serialize the effective value of the Actions property on instances of this class.
Protected method ShouldSerializePropertyReturns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Public method VerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method IAddChildAddChildInfrastructure. Adds a child object.
Explicit interface implemetation Private method IAddChildAddTextInfrastructure. Adds the text content of a node to the object.
Top
Remarks

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. For example, you may want to use an EventTrigger to start a set of animations when the mouse pointer is over a certain user interface (UI) control. 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.

Note that when using an EventTrigger, you need to choose events that do not interfere with the inherent behavior of your control. Controls such as Button or TextBox perform specific actions on user input events such as mouse clicks and keyboard events. 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. Instead, you can use the PreviewMouseDown event or a different event.

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.

Adding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object.

Examples

This example shows how to use event triggers in a style to animate the MouseEnter and MouseLeave events of a FrameworkElement. In this example, the Style has the TargetType set to Rectangle. 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>
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.