Windows 8 apps - simple animation when button is c

2019-08-05 04:12发布

问题:

so I'm putting 2 same-sized StackPanels in the same position. The Visibility of the first StackPanel is Visible, while the second is Collapsed. Then I add this code to my button:

    private async void Button_Clicked(object sender, RoutedEventArgs e)
    {
         StackPanel1.Visibility = Visibility.Collapsed;
         StackPanel2.Visibility = Visibility.Visible;
    }

this simply makes the first StackPanel gone and the second to be visible.

However, I would like to add a simple animation that will make the first StackPanel fade off to the left to disappear and the second StackPanel comes to alive from the right. Is this possible?

回答1:

You can see this MSDN post about animations. the animation you're looking for is the fade in/out animation. You'll find the code of the fade in animation here