Setting Boolean ViewModel Property Inside Storyboard

I have a storyboard called by a property in the ViewModel, this triggers the animation to run. But how do I return the Saved property to False when this is done using animation (to run 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> 
+4
source share
2 answers

If you can transfer to your property, I would recommend a BooleanAnimationUsingKeyFrames with a discrete frame at the end of your term.

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

Since you are using a binding to Saved , I assume that using a DataContext should work.

+7
source

You can use ObjectAnimationUsingKeyFrames to set the property. I'm not quite sure if other animations can be used, 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> 
+5
source

Source: https://habr.com/ru/post/1347887/


All Articles