.net - 当 ListView 单元格中的值发生变化时闪烁颜色

标签 .net wpf

我有一个ListView(如下所示)。我希望当显示的值发生变化时,单元格会闪烁一种颜色(理想情况下一种颜色表示增加,一种颜色表示减少)。

我知道如何编写颜色动画(如下),并且我很确定我需要使用单元格模板,这样我就可以将触发器连接到样式来启动动画。我只是不确定将扳机卡在哪里的最佳位置。

我希望能够连接到 PropertyChanged 事件,但我不确定如何连接。

    <ListView ItemsSource="{Binding MyListItems}">
        <ListView.View>
            <GridView>                
                <GridViewColumn Header="Value1" Width="50" CellTemplate="{StaticResource Value1CellTemplate}" />
                <GridViewColumn Header="Value2" Width="50" DisplayMemberBinding="{Binding Value2}" />
            </GridView>
        </ListView.View>
    </ListView>

单元格模板和颜色动画:

    <DataTemplate x:Key="Value1CellTemplate">
        <TextBlock Text="{Binding LowerBound}" HorizontalAlignment="Right" />
    </DataTemplate>

    <Storyboard x:Key="IncreaseValueColourAnimation" Duration="0:0:2">
        <ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames.KeyFrames>
                <LinearColorKeyFrame Value="Red" KeyTime="0:0:0.1" />
                <LinearColorKeyFrame Value="Transparent" KeyTime="0:0:2" />
            </ColorAnimationUsingKeyFrames.KeyFrames>
        </ColorAnimationUsingKeyFrames>
    </Storyboard>

最佳答案

我相信您正在寻找 FrameworkElement 之外的 TargetUpdated 事件。

Occurs when the target value changes for any property binding on this element.

然后您应该能够使用 EventTrigger 来运行动画。

关于.net - 当 ListView 单元格中的值发生变化时闪烁颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2379668/

相关文章:

.net - 如何使用 .NET 中的智能卡对 PDF 文件进行数字签名?

c# - 长时间运行的查询 Web 应用程序( azure )解决方案

.net - 单独的 Web 服务中的相同类型

c# - 单击 gridview 列标题整个 gridview 试图覆盖窗口

wpf - 如何单向绑定(bind)到 materialDesign :ButtonProgressAssist. IsIndicatorVisible DependencyProperty

.net - ClickOnce appref.ms 参数

c# - WCF 代理 - 同时使用 SOAP 1.1 和 1.2

c# - 组合框的两种方式数据绑定(bind)问题 - WPF

wpf - WPF:基于另一个组件中的样式的样式

c# - Catel - CommandManager 未传递 CommandParameter