views:

495

answers:

2

If I have a BooleanAnimation that sets a property, that property becomes locked and can't be changed by any other means.

Example:

<EventTrigger
    SourceName="myButton"
    RoutedEvent="Button.Click">
    <EventTrigger.Actions>
        <BeginStoryboard>
            <Storyboard>
                <BooleanAnimationUsingKeyFrames
                    Storyboard.TargetName="myCheckBox"
                    Storyboard.TargetProperty="IsChecked"
                    FillBehavior="HoldEnd">
                    <DiscreteBooleanKeyFrame
                        KeyTime="00:00:00"
                        Value="False" />
                </BooleanAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger.Actions>
</EventTrigger>

In this example, if the button is clicked the checkbox is set to false, however, if the user attempts to check the checkBox again the checkbox is unresponsive. The IsChecked property can't be set through code either (after the button has been clicked).

I can create another animation that will update the CheckBox, but that's not the behavior I require.

I've also tried FillBehavior="Stop", but that just causes the Animation not to work either.

+2  A: 

The CheckBox is still being set, but the animation is still running, which is why it appears to be unchecking it. There are a few ways that this can be fixed so that the animation no longer controls the property on the checkbox. The MSDN Animation overview talks about what happens when the animation ends. And how to set a Property after animating it with a Storyboard goes over some other options.

rmoore
Ok, yes I see how the animation is working now. Unfortunately, this means that I can't set a property with an EventTrigger, unless I lock that property using "HoldEnd". The link for "how to set a property after animating it with a Storyboard", will only work when there's a code behind available. For this particular instance I'm trying to keep within the XAML as it's a custom control. I'll create a new question.
Chris Nicol
A: 

replace FillBehavior="HoldEnd" with Duration="00:00:01" FillBehavior="Stop"

and it will work :-)

Myz