以下代码在Silverlight中可以正常运行:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    Storyboard storyboard = new Storyboard();
    DoubleAnimation doubleAnimation = new DoubleAnimation();
    doubleAnimation.From = 50;
    doubleAnimation.To = 100;
    doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
    doubleAnimation.AutoReverse = true;
    doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
    storyboard.Children.Add(doubleAnimation);
    Storyboard.SetTarget(doubleAnimation, button1);
    Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));
    storyboard.Begin();
}

在WinRT / Metro中,需要进行一些小的更改才能进行编译:
Storyboard.SetTargetProperty(doubleAnimation, "Width");

但是当您运行它时,什么也没发生。

如果将属性从“宽度”更改为“不透明度”(同时将From = 0和To = 1更改),将起作用。

“宽度”有什么问题?

最佳答案

您需要添加以下内容:

doubleAnimation.EnableDependentAnimation = true;

这似乎解决了问题。

关于c# - 隐藏代码中的WinRT/Metro动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11260529/

10-11 04:10