在情节提要中设置ViewModel布尔属性 [英] Setting a ViewModel boolean property inside a storyboard

查看:49
本文介绍了在情节提要中设置ViewModel布尔属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板,它是由ViewModel中的一个属性触发的,这触发了动画的开始.但是,当动画完成后,如何将"Saved"属性设置回 False (触发ExitAction.)

I have a storyboard that's triggered by a property in the ViewModel, this trigger the animation to start. But how do I set the "Saved" property back to False when it is done with the animation (to trigger the ExitAction.)

<Style TargetType="TextBlock" x:Key="FadeInOut">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Saved}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" From="0" To="1" />
                            <!-- set "Saved" to false when done -->
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" From="1" To="0"  />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>

推荐答案

如果可以导航到属性,我建议使用

If you can navigate to your property i would recommend a BooleanAnimationUsingKeyFrames with a discrete frame at your end-time.

<BooleanAnimationUsingKeyFrames
            Storyboard.TargetProperty="DataContext.Saved"
            FillBehavior="HoldEnd">
            <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:1" />
</BooleanAnimationUsingKeyFrames>

由于您使用了 Saved 的绑定,因此我认为使用DataContext应该可以.

Since you use a binding to Saved i assume using the DataContext should work.

这篇关于在情节提要中设置ViewModel布尔属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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