Creating an Animation when DataGridCell's Bound Value is Updated
All I have the following 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>
<DataGridTextColumn Header="KeyIndex" Binding="{Binding KeyIndex}"
IsReadOnly="True"/>
<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>
when a row in the data set is removed I want to re-number the KeyIndex
column. When this renumbering takes place I want to elegantly flash the
updated cells letting the user know then these values were updated.
I am still relatively new to WPF and MVVM and I am unsure how to 'listen'
for this change in value. My first thought was that I don't need a new
DependencyProperty for this job, and could do this my merely hooking into
the SourceUpdated property using a DataTrigger but it is not clear how to
do this. I have attempted to define the following
<Style x:Key="readOnlyCellUpdatedStyle"
TargetType="{x:Type DataGridCell}"
BasedOn="{StaticResource {x:Type DataGridCell}}">
<Style.Triggers>
<DataTrigger Binding="ContentUpdated" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1"
Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0.25"
Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
But binding to a ContentUpdated property for each item in the ViewModel is
far from ideal. What is the correct way to do what I want?
Thanks for your time.
No comments:
Post a Comment