1
votes

I have an animation that expand / collapse some StackPanels, in the window there are some ToggleButtons that must be unchecked when the StackPanel is collapsed. I have the animation like this:

<Storyboard x:Key="cmdUnchecked">
   <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StackPanel1" Storyboard.TargetProperty="(FrameworkElement.Height)">
      <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="37"/>
   </DoubleAnimationUsingKeyFrames>
</Storyboard>

This hides the StackPanel, but I need to uncheck the ToggleButton from other events.

Is it possible to uncheck the ToggleButton From this StoryBoard?

An if so, do I need to verify if it's already checked / unchecked?

2

2 Answers

1
votes

You can use an ObjectAnimationUsingKeyFrames like so:

<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="YourToggleButton" Storyboard.TargetProperty="(ToggleButton.IsChecked)">
    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="False" />
</ObjectAnimationUsingKeyFrames>

You should not need to check if it's already checked since setting it to false when it's already false should have no side effects.

1
votes

You should use BooleanAnimations to animate Boolean values:

     <BooleanAnimationUsingKeyFrames Storyboard.TargetName="YourToggleButton" Storyboard.TargetProperty="IsChecked">
           <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0"/>
     </BooleanAnimationUsingKeyFrames>

You can put your DoubleAnimations in ToggleButton.Triggers as EventTriggers on RoutedEvents Checked and Unckecked, then just check/unckeck the toggle button with BooleanAnimation and ToggleButton will automatically run the double animations to change height of stackpanel