EventTrigger Object
Represents a trigger that applies a set of actions (animation storyboards) in response to an event.
XAML | |
Scripting |
To create an object using scripting, see CreateFromXAML.
|
XAML Values
oneOrMoreBeginStoryboards | One or more BeginStoryboard object elements. Object elements defined here become members of the collection held by the Actions property, when accessed by scripting at runtime. |
Properties
Methods
Equals, FindName, GetHost, GetValue, SetValue
Remarks
You do not typically specify Actions as an explicit property element in XAML, because it is the default collection property of an EventTrigger. You will set the Actions value in XAML by placing one or more BeginStoryboard elements as the child elements of an EventTrigger object element.
EventTrigger itself is always a child element of the <object.Triggers> property element when specified in XAML. The Triggers property is a case where the property element syntax is required to set it in XAML.
In Silverlight 1.0, the only event that you can use for an EventTrigger is the Loaded event. For other events, you should declare a storyboard in Resources, provide the storyboard a Name, and write an event handler that calls Begin on the named storyboard. For details, see Interactive Animations Overview.
Examples
The following example shows how to use a Storyboard and an EventTrigger to make a rectangle that fades in and out of view after it is loaded.
XAML |
---|
<Canvas xmlns="https://schemas.microsoft.com/client/2007" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"> <Rectangle x:Name="MyAnimatedRectangle" Width="100" Height="100" Fill="Blue"> <Rectangle.Triggers> <!-- Animates the rectangle's opacity. --> <EventTrigger RoutedEvent="Rectangle.Loaded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="MyAnimatedRectangle" Storyboard.TargetProperty="Opacity" From="1.0" To="0.0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Rectangle.Triggers> </Rectangle> </Canvas> |
See Also
Animation Overview
Interactive Animations Overview
BeginStoryboard