【问题标题】:ColorAnimation to animate the listviewItem color on Swipe - WP8.1ColorAnimation 在滑动时为 listviewItem 颜色设置动画 - WP8.1
【发布时间】:2014-10-15 09:48:13
【问题描述】:

我正在尝试使用以下故事板在向右滑动时更改列表视图项目的颜色,但它会引发异常

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

这是我使用的代码。这是写在操作Delta事件中

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();
         }

【问题讨论】:

  • 您可以在答案框中回答自己的问题,然后标记为已回答
  • @thumbmunkeys 是的。做到了。

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


【解决方案1】:

找到解决方案:D 是 TargetProperty 导致了异常。您需要将目标属性设置如下

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

而不是

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

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 2015-05-18
    • 2022-01-13
    相关资源
    最近更新 更多