布尔动画锁定属性 [英] Boolean Animation locks property

查看:30
本文介绍了布尔动画锁定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个设置属性的 BooleanAnimation,该属性将被锁定并且无法通过任何其他方式进行更改.

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

示例:

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

在此示例中,如果单击按钮,则复选框将设置为 false,但是,如果用户尝试再次选中复选框,则复选框将无响应.IsChecked 属性也不能通过代码设置(点击按钮后).

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

我可以创建另一个动画来更新 CheckBox,但这不是我需要的行为.

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

我也尝试过 FillBehavior="Stop",但这只会导致动画无法正常工作.

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

推荐答案

CheckBox 仍在设置中,但动画仍在运行,这就是它似乎未选中它的原因.有几种方法可以解决这个问题,以便动画不再控制复选框上的属性.MSDN Animation 概述讨论了动画结束时会发生什么.以及 如何在使用故事板介绍了一些其他选项.

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.

这篇关于布尔动画锁定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆