在 AddNew 或 EditItem 事务期间不允许 DeferRefresh

jue*_*n d 1 c# wpf datagrid mvvm

我有一个包含 2 个 DataGrid 的窗口。如果我从第一个 DataGrid 中的一个特定列单击到另一个 DataGrid 的任何列,则会出现错误

在 AddNew 或 EditItem 事务期间不允许 DeferRefresh

这里出了什么问题?

第一个 DataGrid 是

<DataGrid x:Name="FirstDataGrid"
          ItemsSource="{Binding Parts, Mode=TwoWay}"
          SelectedItem="{Binding SelectedPart, Mode=TwoWay}"
          CellEditEnding="DataGrid_OnCellEditEnding" >
     <i:Interaction.Behaviors>
          <views:ScrollIntoViewBehavior />
     </i:Interaction.Behaviors>
          <DataGrid.Resources>
               <Style TargetType="{x:Type DataGridCell}">
                   <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
               </Style>
          </DataGrid.Resources>
      <DataGrid.Columns>
          <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ItemsControl ItemsSource="{Binding Identifications, Mode=OneWay}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Margin="5,0,0,0">
                                            <Hyperlink NavigateUri="{Binding ArticleNumber, Mode=OneWay}" 
                                                        Command="{Binding ElementName=PartDataGrid, Path=DataContext.OpenIdentificationCommand}" CommandParameter="{Binding}" >                                    
                                                <TextBlock Text="{Binding ArticleNumber, Mode=OneWay}"/>
                                            </Hyperlink>
                                        </TextBlock>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
      </DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

第二个 DataGrid 无关紧要,因为我可以单击任何列来产生错误。

jue*_*n d 5

我自己解决了。

导致问题的列是只读的。那么为什么要允许编辑模式呢?那显然是错误的。我通过添加解决了这个问题

IsReadOnly="True"
Run Code Online (Sandbox Code Playgroud)

到 WPF 列定义。