我有以下所有DataGrid
<DataGrid x:Name="resourceDataGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoGenerateColumns="false"
GridLinesVisibility="None"
RowHeaderWidth="0"
CanUserAddRows="True"
CanUserDeleteRows="True"
ItemsSource="{Binding Path=Resources,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,
IsAsync=True}">
<DataGrid.Columns>
<DataGridTemplateColumn CellTemplate="{StaticResource readOnlyCellUpdatedStyle}" IsReadOnly="True"/>
<!--<DataGridTextColumn Header="KeyIndex" Binding="{Binding KeyIndex}" IsReadOnly="True"/>--> <- What I did have...
<DataGridTextColumn Header="FileName" Binding="{Binding FileName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ResourceName" Binding="{Binding ResourceName}" IsReadOnly="False"/>
<controls:CollectionTextColumn Collection="ResourceStringList" Visibility="Collapsed"/>
</DataGrid.Columns>
</DataGrid>
当数据集中的一行被删除时,我想重新编号该KeyIndex
列。当这种重新编号发生时,我想优雅地闪烁更新的单元格,让用户知道然后这些值被更新。
我创建了以下DataTemplate
<DataTemplate x:Key="readOnlyCellUpdatedStyle">
<TextBlock Text="{Binding KeyIndex, NotifyOnSourceUpdated=True, Mode=TwoWay}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<EventTrigger RoutedEvent="Binding.SourceUpdated">
<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>
绑定仍然适用,KeyIndex
但是当我KayIndex
从 ViewModel 更新值时,动画会发生,值只会发生变化。为什么更新时动画不触发KeyIndex
?
谢谢你的时间。