更新了绑定源上单个数据网格单元的动画背景

时间:2012-11-06 15:15:49

标签: c# wpf mvvm datagrid

我想在更新源时更改数据网格中单个单元格的背景。我正在使用MVVM,C#和WPF:

这是我的xaml文件中没有工作的代码(只有datacell本身):

<DataGridTextColumn x:Name="test" Header="Errors" IsReadOnly="True" Binding="{Binding ErrorsReceived}">
    <DataGridTextColumn.CellStyle>
                    <EventTrigger RoutedEvent="Binding.SourceUpdated">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="test"
                                            Storyboard.TargetProperty="Background"
                                            From="Red"
                                            To="White"
                                            Duration="0:0:0.2"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>

我该如何做到这一点?

1 个答案:

答案 0 :(得分:1)

还没有机会运行它但是你试图设置一个没有定义样式的样式,并且你试图用双动画设置颜色动画,试试这样的事情。

<DataGridTextColumn Header="Errors" IsReadOnly="True" Binding="{Binding ErrorsReceived}">
            <DataGridTextColumn.CellStyle>
                 <Style>
                     <Style.Triggers>
                         <EventTrigger RoutedEvent="Binding.SourceUpdated">
                              <BeginStoryboard>
                                  <Storyboard>
                                      <ColorAnimation Storyboard.TargetProperty="Background" From="Red" To="White" Duration="0:0:0.2"/>
                                   </Storyboard>
                            </BeginStoryboard>
                     </EventTrigger>
                       </Style.Triggers>
               </Style>
           </DataGridTextColumn.CellStyle>
     </DataGridTextColumn >