2013-04-13 45 views
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); 
    } 

请帮我...

回答

0

您将要开始对TableRowBackground属性在动画,因为你需要为目标的SolidColorBrush

例的Color属性:

tr.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation); 
+0

谢谢兄弟。 – Kernel