user1202434
user1202434

Reputation: 2273

disable animation in XAML?

If i have a storyboard animation defined in xaml resources, how do i go about disabling it?

For example, if I have something like this on a UserControl.Resources section:

<Storyboard x:Key="MyKey">
        <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:.5" DecelerationRatio="1" />
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>

IS there a way to disable the animation in xaml..?

Upvotes: 3

Views: 2871

Answers (1)

Sascha
Sascha

Reputation: 10347

A XAML way is described here: http://msdn.microsoft.com/en-us/library/ms741997.aspx

Code behind: You can use FindResource to get the StoryBoard, cast it to a StoryBoard and call Stop.

Edit: See http://www.galasoft.ch/mydotnet/articles/article-2006102701.aspx for a deeper look into storyboards and code behind.

Edit: Using Properties within triggers:

<MultiTrigger>
    <MultiTrigger.Conditions>
        <Condition Property="IsActive" Value="True"/>
    </MultiTrigger.Conditions>
    <MultiTrigger.EnterActions>
        <BeginStoryboard Storyboard="{StaticResource StoryBoard1}"/>
    </MultiTrigger.EnterActions>
    <MultiTrigger.ExitActions>
        <BeginStoryboard Storyboard="{StaticResource StoryBoard2}"/>
    </MultiTrigger.ExitActions>
</MultiTrigger>

Upvotes: 1

Related Questions