的WinRT /地铁动画代码隐藏(WinRT/Metro Animation in code-beh

2019-09-18 18:20发布

下面的代码在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的/地铁,它需要一个小的改动,使其编译:

Storyboard.SetTargetProperty(doubleAnimation, "Width");

但是当你运行它,什么都不会发生。

如果从“宽”到“不透明度”更改属性(也改变从= 0,为= 1)的作品。

什么是“宽”的问题?

Answer 1:

您需要添加以下内容:

doubleAnimation.EnableDependentAnimation = true;

这似乎解决问题。



Answer 2:

我不知道,但尝试使用:

Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty);

代替

Storyboard.SetTargetProperty(doubleAnimation, "Width");


文章来源: WinRT/Metro Animation in code-behind