我的代码是这样的。我想动态创建网格。创造就是成功,但我无法为它的颜色设置动画。我的错误是什么?
Grid[] grid = new Grid[99];
for (int i = 0; i < 10; i++) {
grid[i] = new Grid();
grid[i].Width = grid[i].Height = 100;
grid[i].Background = Brushes.WhiteSmoke;
Storyboard sb = new Storyboard();
ColorAnimation ca = new ColorAnimation(Colors.DarkTurquoise, TimeSpan.FromMilliseconds(250));
Storyboard.SetTarget(ca, grid[i]);
Storyboard.SetTargetProperty(ca, new PropertyPath("Fill.Color"));
sb.Children.Add(ca);
grid[i].MouseEnter += delegate(object sender2, MouseEventArgs e2) {
sb.Begin(this);
};
stackMain.Children.Add(grid[i]);
}