1

私が持っているのは次のすべてです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>

データセットの行が削除されたときに、列の番号を付け直したいKeyIndex。この再番号付けが行われると、更新されたセルをエレガントにフラッシュして、これらの値が更新されたことをユーザーに知らせたいと思います。

私はまだWPFとMVVMに比較的慣れていないため、この値の変化を「聞く」方法がわかりません。私が最初に考えたのは、DependencyPropertyこの仕事には new は必要なく、 aSourceUpdatedを使用してプロパティに接続するだけでこれを行うことができるというDataTriggerことでしたが、これを行う方法は明確ではありません。私は以下を定義しようとしました

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

しかしContentUpdated、ViewModel 内の各項目のプロパティへのバインドは、理想とはほど遠いものです。私がやりたいことをする正しい方法は何ですか?

御時間ありがとうございます。

4

1 に答える 1

2

SourceUpdated私が過去にこれを行った方法ですが、 でNotifyOnSourceUpdatedtrue に設定していることを確認する必要がありますBinding。何かのようなもの:

<DataGridTemplateColumn>
    <DataGridTemplateColumn.Template>
        <DataTemplate>
            <TextBlock Text="{Binding KeyIndex, NotifyOnSourceUpdated=True, Mode=OneWay}">
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Style.Triggers>
                            <EventTrigger RoutedEvent="Binding.SourceUpdated">
                                ...
                            </EventTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </DataTemplate>
    </DataGridTemplateColumn.Template>
</DataGridTemplateColumn>
于 2013-08-08T00:02:21.973 に答える