Windows 8 metro app - animating a stack panel?

2019-06-11 05:52发布

问题:

I'm making a button that will disappear my stack panel:

public void myButton (object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
     myStackPanel.Visibility = Visibility.Collapsed;
}

However, I would also like to perform a little animation when getting rid of that stack panel.

Just a simple animation like fading from left to right. What codes should I add on my myButton?

回答1:

You can use a FadeOutThemeAnimation, as described here: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.media.animation.fadeoutthemeanimation.aspx.



回答2:

If you want to do something right there in your codebehind, you could try something like this.

DoubleAnimation fadeout = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(2), FillBehavior.HoldEnd);
fadeout.BeginTime = TimeSpan.FromSeconds(0);
Storyboard sb = new Storyboard();
Storyboard.SetTarget(fadeout, myStackPanel);
Storyboard.SetTargetProperty(fadeout, new PropertyPath("(Opacity)"));
sb.Children.Add(fadeout);
sb.Begin();