绑定源上单个datagrid单元的动画背景已更新 [英] Animate background of single datagrid cell on binding source updated

查看:56
本文介绍了绑定源上单个datagrid单元的动画背景已更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to changed the background of a singe cell in a datagrid when the source is updated. I am using MVVM, C# and WPF:

这是xaml文件(仅数据单元本身)中不起作用的代码:

Here is my not working code form the xaml file (only the datacell itself):

<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>

如何进行这项工作?

推荐答案

还没有机会运行它,但是您尝试设置样式但未定义样式,并且尝试使用双重动画为颜色设置动画,请尝试

Haven't had a chance to run it yet but you've tried to set a style without a style being defined and you're trying to animate a color with a double animation, try something like this.

<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 >

这篇关于绑定源上单个datagrid单元的动画背景已更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆