问题
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>
回答1:
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.
回答2:
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>
来源:https://stackoverflow.com/questions/5647452/setting-a-viewmodel-boolean-property-inside-a-storyboard