我创建了一个表,当 MouseMove 发生时,我想更改 TableRow 的背景颜色,并且当 MouseLeave 发生时,它会回到 TableRow 的旧颜色。这是编码,但它不起作用。
currentRow.MouseMove += new MouseEventHandler(ShowRowColor);
currentRow.MouseLeave += new MouseEventHandler(HideRowColor);
void ShowRowColor(object sender, System.Windows.Input.MouseEventArgs e){
TableRow tr = sender as TableRow;
ColorAnimation animation = new ColorAnimation();
animation.From = (tr.Background as SolidColorBrush).Color;
animation.To = Colors.Indigo;
animation.Duration = new Duration(TimeSpan.FromSeconds(5));
tr.BeginAnimation(SolidColorBrush.ColorProperty,animation);
}
void HideRowColor(object sender, System.Windows.Input.MouseEventArgs e) {
TableRow tr = sender as TableRow;
ColorAnimation animation;
animation = new ColorAnimation();
animation.From = Colors.Indigo;
animation.To = (tr.Background as SolidColorBrush).Color;
animation.Duration = new Duration(TimeSpan.FromSeconds(1));
tr.BeginAnimation(SolidColorBrush.ColorProperty,animation);
}
请帮我...