tags:

views:

523

answers:

3
<Grid.Triggers>
    <EventTrigger RoutedEvent="Border.Loaded">
            <EventTrigger.Actions >
                    <BeginStoryboard>
                            <Storyboard x:Name="MyStoryboard"    AutoReverse="True" RepeatBehavior="Forever">
                                  <ColorAnimationUsingKeyFrames    BeginTime="00:00:00"  Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                                       <SplineColorKeyFrame KeyTime="00:00:01" Value="#FFFAFAFA"/>
                                  </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                    </BeginStoryboard>
            </EventTrigger.Actions>
    </EventTrigger>
</Grid.Triggers>

How do I enable\disable this event trigger\animation dynamically. I was thinking I could bind to a IValueConverter and disable the storyboard, but there does not seem to be any suitable property to bind to?

+1  A: 

The only trigger currently available in Silverlight is "Loaded", for all other events you'll have to write a bit of code. To use this technique, Storyboards should go in the Resources section instead of Triggers, and you'll call Begin() on the Storyboard from the code.

If you're doing templating of a control, then there are what are called Transitions which let you kick off storyboards based on control events, like MouseOver. This is handled by the Visual State Manager:

http://timheuer.com/blog/archive/2008/06/04/silverlight-introduces-visual-state-manager-vsm.aspx

Bill Reiss
A: 

I wasn't really looking for the animation to be turned off based on an event. I wanted to do it based on a property of my business object that Im binding too? I was hoping there was something like Storyboard.Enabled = False!?!?!

Dan
A: 

You can't do what you are asking for with triggers in Silverlight. There's not a way to have a conditional in the trigger. You can wire up the Loaded event, check your condition there, and if it's met start the storyboard. However, there is not a XAML-only equivalent.

bennage