如何在WPF中更改TableRow的背景颜色?

时间:2013-04-13 08:28:52

标签: c# wpf wpfdatagrid

我创建了一个表,当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);
    }

请帮助我......

1 个答案:

答案 0 :(得分:0)

您需要在Background的{​​{1}}属性上启动动画,因为您需要定位TableRow的{​​{1}}属性

示例:

Color