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?
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.
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();