我正在尝试在 Windows 8 Metro 应用程序中为边框控件的宽度设置动画。我设法为边框上的其他属性设置动画,例如不透明度:
private void Item_Tapped(object sender, RoutedEventArgs e)
{
var border = sender as Border;
var animation = new DoubleAnimation();
animation.To = 0.0;
animation.Duration = new Duration(TimeSpan.FromSeconds(1));
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
Storyboard.SetTarget(animation, border);
Storyboard.SetTargetProperty(animation, "Opacity");
storyboard.Begin();
}
但是当我尝试为控件的宽度设置动画时:
private void Item_Tapped(object sender, RoutedEventArgs e)
{
var border = sender as Border;
var animation = new DoubleAnimation();
animation.To = 600.0;
animation.Duration = new Duration(TimeSpan.FromSeconds(1));
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
Storyboard.SetTarget(animation, border);
Storyboard.SetTargetProperty(animation, "Width");
storyboard.Begin();
}
没发生什么事。
我可以在 WPF 中执行此操作,但不能在 Windows 8 中执行此操作。这是 Metro 的限制或错误,还是我做错了什么?
谢谢