gpt4 book ai didi

c# - ColorAnimation 为滑动时的 listviewItem 颜色设置动画 - WP8.1

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:39 25 4
gpt4 key购买 nike

我正在尝试使用以下 Storyboard向右滑动更改 ListView 项目的颜色,但它引发了一个异常

WinRT information: ColorAnimation cannot be used to animate property Background due to incompatible type. Additional information: No installed components were detected.

这是我用过的代码。这个写在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();
}

最佳答案

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

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

不是

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

关于c# - ColorAnimation 为滑动时的 listviewItem 颜色设置动画 - WP8.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26379399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com