我正在设置DataGridRow BackgroundColor
为绿色或红色,并根据LogError
值触发。
我想用透明度为新添加的行设置动画。
这工作正常:
From="Transparent" To="Red"
但我想要颜色去的是当前的颜色设置与样式。它并不总是红色,它也可能是绿色。
这不起作用:
From="Transparent" To="{TemplateBinding DataGridRow.Background}"
或者
From="Transparent" To="{Binding RelativeSource={RelativeSource Self}, Path=Backgound}"
代码:
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property = "Background" Value="LimeGreen"/>
<Style.Triggers>
<DataTrigger Binding="{Binding LogMessage}" Value="Exception has occured">
<Setter Property = "Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="(DataGridRow.Background).(SolidColorBrush.Color)"
Duration="00:00:03"
From="Transparent"
To="{TemplateBinding DataGridRow.Background}"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
错误信息:Cannot freeze this Storyboard timeline tree for use across threads.