【发布时间】:2013-08-13 00:16:26
【问题描述】:
所有,在这个回答https://stackoverflow.com/a/18136371/626442 上一个问题中,回答为我的动画不触发的问题提供了一个解决方案。代码是
<DataTemplate x:Key="readOnlyCellUpdatedStyle">
<TextBlock Text="{Binding KeyIndex, Mode=TwoWay,NotifyOnTargetUpdated=True}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
Duration="0:0:0.3"
From="White"
To="Red"
RepeatBehavior="3x"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
当我通过 ViewModel 更新 KeyIndex 列时,这会触发动画。但是,我只希望 DataGridTextColumn 的单元格的动画在值更新时进行动画处理,但它们也会在 DataGrid 滚动时触发。有人建议我
创建具有您需要的内置功能的派生
DataGridTextColumn可能是更好的选择,因为如果您使用虚拟化,则几乎不可能使用TargetUpdated。但如果你自定义了DataGridTextColumn,你应该可以让它工作。
如何创建自定义/派生的 `DataGridTextColumn(我也可以使用 blend)?
我不知道该怎么做,而且关于这个特定概念的文档很少。
感谢您的宝贵时间。
【问题讨论】:
标签: c# wpf mvvm user-controls wpfdatagrid