c# - 代码隐藏中的 WinRT/Metro 动画

标签 c# windows-runtime winrt-xaml

以下代码在 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/

相关文章:

c# - 从 PDF 文档 c# 中读取日期字符串(2012 年 2 月 1 日)

c# - 在以下情况下如何确保不发生内存泄漏

windows-8 - WinRT 广告替代 Microsoft Pubcenter

windows-8 - CreateFile2 在 Windows 8 中返回访问被拒绝错误

c# - 即使已添加转换器,也不会调用 Windows Phone 8.1 图像分辨率转换器

c# - 将图像复制并重命名到 Windows 8 应用程序上的文件夹

C# 区分静态 GIF 和动画 GIF

c# - 为什么 c# 编译器在某些情况下会发出 newobj/stobj 而不是 'call instance .ctor' 来进行结构初始化

c# - 如何在 XAML/C# (Windows 8.1 - WinRT) 上水平和垂直虚拟化 "datagrid like"控件

c# - 如何在 Win10 的新 Outlook 应用程序中实现滑动手势?