EventTrigger EventTrigger EventTrigger Class

Represents a trigger that applies a set of actions (animation storyboards) in response to an event. Not commonly used. See Remarks.

Syntax

Declaration

public sealed class EventTriggerpublic sealed class EventTriggerPublic NotInheritable Class EventTrigger
<EventTrigger>
  oneOrMoreBeginStoryboards
</EventTrigger>
 

Inheritance Hierarchy

Remarks

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:

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 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.

Examples

This XAML example shows the basic structure for using Triggers with its default 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>

Constructors summary

Initializes a new instance of the EventTrigger class.

Properties summary

Gets the collection of BeginStoryboard objects that this EventTrigger maintains.

Gets or sets the name of the event that initiates the trigger. Not commonly set, see Remarks.

Constructors

  • EventTrigger()
    EventTrigger()
    EventTrigger()
    EventTrigger()

    Initializes a new instance of the EventTrigger class.

    public EventTrigger()public New()Public Sub New()public EventTrigger()

Properties

  • Actions
    Actions
    Actions
    Actions

    Gets the collection of BeginStoryboard objects that this EventTrigger maintains.

    public TriggerActionCollection Actions { get; }public TriggerActionCollection Actions { get; }Public ReadOnly Property Actions As TriggerActionCollectionpublic TriggerActionCollection Actions { get; }
    <EventTrigger>
      oneOrMoreBeginStoryboards
    </EventTrigger>
     
    

    Property Value

  • RoutedEvent
    RoutedEvent
    RoutedEvent
    RoutedEvent

    Gets or sets the name of the event that initiates the trigger. Not commonly set, see Remarks.

    public RoutedEvent RoutedEvent { get; set; }public RoutedEvent RoutedEvent { get; set; }Public ReadWrite Property RoutedEvent As RoutedEventpublic RoutedEvent RoutedEvent { get; set; }

    Property Value

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.UI.Xaml.Markup.ContentPropertyAttribute

Details

Assembly

Windows.UI.Xaml.dll