ColorAnimation在Swipe-WP8.1上为listviewItem颜色设置动画

时间:2014-10-15 09:48:13

标签: c# windows-phone-8 windows-runtime listviewitem coloranimation

我正在尝试使用以下故事板更改右侧滑动列表视图项的颜色,但它会抛出一个异常,表示

  

WinRT信息:由于类型不兼容,ColorAnimation无法用于动画属性背景。   附加信息:未检测到已安装的组件。

这是我用过的代码。这是在manipulationDelta事件

中编写的
Grid ChannelGrid = (Grid)sender;
Grid DeleteGrid = (Grid)((Grid)(ChannelGrid.Parent)).Children[1];

网格是listviewitem的项目模板,并且操纵事件已连接到该模板。

else if (e.Position.X - initialpoint.X > 30 && ChannelGrid.Width == 380) // Swipe right
        {
            e.Complete();
            Storyboard SwipeRight = new Storyboard();

            ColorAnimation changeColorAnimation = new ColorAnimation();
            changeColorAnimation.EnableDependentAnimation = true;
            changeColorAnimation.To = Colors.Green;
            changeColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(100));
            Storyboard.SetTarget(changeColorAnimation, ChannelGrid);
            Storyboard.SetTargetProperty(changeColorAnimation, "Background");//**WRONG**
            SwipeRight.Children.Add(changeColorAnimation);
            SwipeRight.Begin();
         }

1 个答案:

答案 0 :(得分:1)

找到解决方案:D这是导致异常的TargetProperty。您需要将target属性设置为以下

PropertyPath p = new PropertyPath("(ChannelGrid.Background).(SolidColorBrush.Color)");
Storyboard.SetTargetProperty(changeColorAnimation, p.Path);

而不是

Storyboard.SetTargetProperty(changeColorAnimation, "Background");//**WRONG**