tags:

views:

238

answers:

1

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 hide 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?

+1  A: 

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.

Drew Marsh
When the ToggleButton is Unchecked it doesn't do anything, and when is checked throws an error "Can not animate property 'IsChecked' on 'System.Windows.Controls.Primitives.ToggleButton' with 'System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames'" Am I doing something wrong?
Luis