Search code examples
wpfstoryboardexpandereventtrigger

expander stuck after isexpanded


I'm using a storyboard and eventTrigger to fire many event when tab is Clicked which works, but after the expander expanded ,the Expander getting stuck after IsExpanded set to true by storyboard

the Question is how i can make the expander Collapsed/Expanded manual again after it sit to to true by storyboard??

<Storyboard x:Key="Operation">


            <BooleanAnimationUsingKeyFrames  Storyboard.TargetProperty="(IsExpanded)" Storyboard.TargetName="ExpanderAnetArticle" FillBehavior="HoldEnd">
                <DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
            </BooleanAnimationUsingKeyFrames>


        </Storyboard>

   </Window.Resources>

    <Window.Triggers>

<EventTrigger RoutedEvent="UIElement.MouseLeftButtonUp" SourceName="CtrlTiOperation">
            <BeginStoryboard x:Name="Operation_BeginStoryboard" Storyboard="{StaticResource Operation}"/>
            <BeginStoryboard x:Name="Tabfocus_BeginStoryboard" Storyboard="{StaticResource Tabfocus}"/>
        </EventTrigger>

Solution

  • Your FillBehavior="HoldEnd" means that you cannot change the property from code because is retained by StoryBoard.

    In a previous answer to your similar question i suggested you to provide Stop value for FillBehavior, but this is wrong because with Stop the value will be reverted at the end of the Animation.

    You can put a completed event in you animation and so something like this:

    private void animation_Completed(object sender, EventArgs e)
    {
      bool isexpanded = Exp1.IsExpanded;
      Exp1.BeginAnimation(Expander.IsExpandedProperty, null);
      Exp1.IsExpanded = isexpanded;
    }
    

    where Exp1 is your Expander.

    You take fhe value, stop the animation and then put the value back. IT works well.

    It's not the only method , but i'm doing some test for myself knowledge.