Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a ViewModel boolean property inside a storyboard

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>
like image 270
Thomas Sandberg Avatar asked Dec 10 '22 09:12

Thomas Sandberg


2 Answers

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>

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

like image 78
H.B. Avatar answered Jan 11 '23 00:01

H.B.


You can use the ObjectAnimationUsingKeyFrames to set the property. I'm not quite sure if you could use other animations but this is the one I recently used.

    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Saved">
        <DiscreteObjectKeyFrame KeyTime="0">
            <DiscreteObjectKeyFrame.Value>
                <system:Boolean>False</system:Boolean>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
like image 28
PVitt Avatar answered Jan 10 '23 23:01

PVitt