【问题标题】:WinRT/Metro Animation in code-behind代码隐藏中的 WinRT/Metro 动画
【发布时间】:2014-08-03 15:41:51
【问题描述】:

以下代码在 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),则可以。

“宽度”有什么问题?

【问题讨论】:

标签: c# windows-runtime winrt-xaml


【解决方案1】:

您需要添加以下内容:

doubleAnimation.EnableDependentAnimation = true;

这似乎解决了问题。

【解决方案2】:

我不确定但尝试使用:

Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty);

代替

Storyboard.SetTargetProperty(doubleAnimation, "Width");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    相关资源
    最近更新 更多