0

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

请帮我...

4

1 回答 1

0

您将希望在 的Background属性上启动动画,TableRow因为您需要定位 的Color属性SolidColorBrush

例子:

tr.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation);
于 2013-04-13T08:52:32.250 回答