Windows 8 metro app - animating a stack panel?

2019-06-11 05:42发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-06-11 06:20

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();
查看更多
登录 后发表回答