我有下面这个网格:
<DataGrid
x:Name="TablesDataGrid"
Grid.Column="0"
Grid.Row="1"
ItemsSource="{Binding FilteredModels.View}"
AlternationCount="2"
AutoGenerateColumns="False"
CanUserSortColumns="True"
CanUserReorderColumns="False"
CanUserDeleteRows="False"
CanUserAddRows="False"
SelectionMode="Extended"
IsReadOnly="False"
SelectionUnit="FullRow"
RowHeight="25"
HorizontalAlignment="Stretch"
ColumnWidth="Auto">
<DataGrid.Columns >
<DataGridCheckBoxColumn Width="*" Binding="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsReadOnly="False">
<DataGridCheckBoxColumn.HeaderTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.CheckAll}"/>
</DataTemplate>
</DataGridCheckBoxColumn.HeaderTemplate>
</DataGridCheckBoxColumn>
<DataGridTextColumn Header="Source Table" Binding="{Binding SourceTableFullName}" Width="4*"></DataGridTextColumn>
<DataGridTextColumn Header="EDW Schema" Binding="{Binding SchemaName}" Width="2*"></DataGridTextColumn>
<DataGridTextColumn Header="EDW Table" Binding="{Binding TableName}" Width="4*"></DataGridTextColumn>
<DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
然后我有一个searchCommand,它在视图模型中执行对collectionViewSource FilteredModels的搜索,然后调用
this.FilteredModels.View.Refresh();
当用户勾选几个复选框并将网格发送到编辑模式,然后执行搜索操作时,我们会收到以下错误。
WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction
当复选框被选中时,或者甚至在单击搜索按钮时,是否有一种方法可以强制网格退出编辑模式?还是有其他解决方法吗?
谢谢!
CommitEdit(DataGridEditingUnit.Row, true);
- Scover