Two way animation

前端 未结 2 688
陌清茗
陌清茗 2021-01-25 03:27

I\'m triying to hide/show a stackpanel when I click in a button. This is what I made so far:


    

        
相关标签:
2条回答
  • 2021-01-25 03:29

    What about a little trick: Together with the storyboard you have in place now, you are hidding the current button and setting another button (which looks the same) visible. The other button has the reverse storyboard, and reverse button visibility settings. With that you don't have to worry about a state, and you can do it only in XAML.

    Other Idea would be to handle the click in the code behind, maintain a flag there, and trigger the storyboard from the code. As this is a view-only functionality I don't see a conflict with MVVM.

    0 讨论(0)
  • 2021-01-25 03:30

    You can change your button to a ToggleButton and use the Checked and Unchecked routed events to set up your 2 storyboards:

    <ToggleButton>
        <ToggleButton.Triggers>
            <EventTrigger RoutedEvent="Checked">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Height"                                                     
                                         Storyboard.TargetName="PanelDeCampos"
                                         From="{Binding ElementName=PanelDeCampos,Path=ActualHeight}" 
                                         To="0" 
                                         Duration="0:0:0.25" />
                    </Storyboard>
    
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="Unchecked">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Height"                                                     
                                         Storyboard.TargetName="PanelDeCampos"
                                         From="0" 
                                         Duration="0:0:0.25"
                                         To="1000" /> <!-- or whatever height you want-->
                    </Storyboard>
    
                </BeginStoryboard>
            </EventTrigger>
        </ToggleButton.Triggers>
    </ToggleButton>
    
    0 讨论(0)
提交回复
热议问题