How to animate a Popup when it hides?

后端 未结 1 1278
后悔当初
后悔当初 2020-12-31 20:02

i created a Popup Style for using in my windows 8.1 application. And i applied PopupThemeTransition to it\'s ChildTransitions Propert

相关标签:
1条回答
  • 2020-12-31 20:51

    This is not native to the Popup because they typically do not have an exit animation. Having said that, there's no reason you can't add an exit animation to a Popup control.

    Try this:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <Storyboard x:Name="ShowPopup">
                <PopInThemeAnimation Storyboard.TargetName="MyPopup" />
            </Storyboard>
            <Storyboard x:Name="HidePopup">
                <PopOutThemeAnimation Storyboard.TargetName="MyPopup" />
            </Storyboard>
        </Grid.Resources>
        <Popup x:Name="MyPopup" IsOpen="True"
               HorizontalAlignment="Center" VerticalAlignment="Center">
            <Popup.Transitions>
                <TransitionCollection>
                    <PopupThemeTransition />
                </TransitionCollection>
            </Popup.Transitions>
            <Grid Height="200" Width="200" Background="Red">
                <StackPanel>
                    <Button Content="Hide (Native)" HorizontalAlignment="Center">
                        <Interactivity:Interaction.Behaviors>
                            <Core:EventTriggerBehavior EventName="Click">
                                <Core:ChangePropertyAction 
                                    PropertyName="IsOpen" 
                                    TargetObject="{Binding ElementName=MyPopup}" />
                            </Core:EventTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>
                    </Button>
                    <Button Content="Hide (Storyboard)" HorizontalAlignment="Center">
                        <Interactivity:Interaction.Behaviors>
                            <Core:EventTriggerBehavior EventName="Click">
                                <Media:ControlStoryboardAction 
                                    Storyboard="{StaticResource HidePopup}"/>
                            </Core:EventTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>
                    </Button>
                </StackPanel>
            </Grid>
        </Popup>
        <StackPanel>
            <Button Content="Show Popup (Native)" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Interactivity:Interaction.Behaviors>
                    <Core:EventTriggerBehavior EventName="Click">
                        <Core:ChangePropertyAction 
                            TargetObject="{Binding ElementName=MyPopup}" 
                            PropertyName="IsOpen" Value="True"/>
                    </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
            </Button>
            <Button Content="Show Popup (Storyboard)" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Interactivity:Interaction.Behaviors>
                    <Core:EventTriggerBehavior EventName="Click">
                        <Core:ChangePropertyAction 
                            TargetObject="{Binding ElementName=MyPopup}" 
                            PropertyName="IsOpen" Value="True"/>
                        <Media:ControlStoryboardAction 
                            Storyboard="{StaticResource ShowPopup}"/>
                    </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
            </Button>
        </StackPanel>
    </Grid>
    

    Using these:

    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" 
    xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:Media="using:Microsoft.Xaml.Interactions.Media"
    

    Best of luck!

    0 讨论(0)
提交回复
热议问题