Represents a trigger that applies a set of actions (animation storyboards) in response to an event. Not commonly used. See Remarks.
public : sealed class EventTrigger : TriggerBase
struct winrt::Windows::UI::Xaml::EventTrigger : TriggerBase
public sealed class EventTrigger : TriggerBase
Public NotInheritable Class EventTrigger Inherits TriggerBase
<EventTrigger> oneOrMoreBeginStoryboards </EventTrigger>
Windows 10 requirements
Windows 10 (introduced v10.0.10240.0)
Windows.Foundation.UniversalApiContract (introduced v1)
This XAML example shows the basic structure for using FrameworkElement.Triggers with its default FrameworkElement.Loaded trigger behavior to run a storyboarded animation. This XAML shows the EventTrigger and BeginStoryboard container elements in proper relationship with each using their XAML content property syntax and unnecessary property element tags omitted.
<Canvas Width="200" Height="200" x:Name="animatedcanvas" Background="Red"> <Canvas.Triggers> <EventTrigger> <BeginStoryboard> <Storyboard x:Name="ColorStoryboard"> <!-- Animate the background of the canvas to green over 4 seconds. --> <ColorAnimation Storyboard.TargetName="animatedcanvas" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" To="Green" Duration="0:0:4"/> </Storyboard> </BeginStoryboard> </EventTrigger> </Canvas.Triggers> </Canvas>
Triggers, EventTrigger, Actions and BeginStoryboard are not commonly used. These API mainly exist for compatibility in XAML originally used for Microsoft Silverlight. For most scenarios where event triggers were used previously, do one of these:
- Use built-in animations from the animation library. See Quickstart: Animating your UI using the animation library.
- For events in control templates, use visual states and VisualStateManager. See Storyboarded animations for visual states or Quickstart: Control templates.
- For app-specific UI animations, define a Loaded handler on the page. This handler can reference a Storyboard that's defined in page-level resources, and call the Begin method on that Storyboard. See Storyboarded animations.
If you do choose to use Triggers, in Windows Runtime XAML, the default behavior for event triggers and the only event that can be used to invoke an EventTrigger is FrameworkElement.Loaded. Because that's both the default and the only enabled behavior, don't set the RoutedEvent attribute. Just use the XAML
<EventTrigger>. If you set RoutedEvent explicitly (not recommended), the only XAML that works is
<EventTrigger RoutedEvent="FrameworkElement.Loaded">. Unqualified "Loaded", or any other value, throws a parse exception. For more info, see Triggers.
|EventTrigger() EventTrigger() EventTrigger() EventTrigger()||
Initializes a new instance of the EventTrigger class.
|Actions Actions Actions Actions|
|Dispatcher Dispatcher Dispatcher Dispatcher||
Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.(Inherited from DependencyObject)
|RoutedEvent RoutedEvent RoutedEvent RoutedEvent||
Gets or sets the name of the event that initiates the trigger. Not commonly set, see Remarks.