0
我創建了一個表,當MouseMove發生時,我想要更改TableRow的背景顏色, 以及MouseLeave發生時,它將返回到TableRow的舊顏色。 這裏是編碼,但它不工作。如何更改WPF中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);
}
請幫我...
謝謝兄弟。 – Kernel