WPF:以编程方式在网格中设置矩形颜色动画
如何以编程方式更改网格中矩形的颜色?
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = Colors.Red;
myColorAnimation.To = Colors.Blue;
myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
myColorAnimation.AutoReverse = false;
myStoryboard = new Storyboard();
myStoryboard.Children.Add(myColorAnimation);
Storyboard.SetTargetName(myColorAnimation, ?); // What do I put here
Storyboard.SetTargetProperty(myColorAnimation, new PropertyPath //What do I put here?
How can I programatically change the Color of a Rectangle in my Grid?
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = Colors.Red;
myColorAnimation.To = Colors.Blue;
myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
myColorAnimation.AutoReverse = false;
myStoryboard = new Storyboard();
myStoryboard.Children.Add(myColorAnimation);
Storyboard.SetTargetName(myColorAnimation, ?); // What do I put here
Storyboard.SetTargetProperty(myColorAnimation, new PropertyPath //What do I put here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了一种方法来做到这一点:
我为每个网格项创建一个故事板:
并填充:
然后我可以像这样制作动画:
OK, I found a way to do this:
I create a StoryBoard for each Grid item:
and populate:
Then I can animate like so: