我有以下网格
<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 对 View 模型中的 collectionViewSource FilteredModels 执行搜索,然后调用
this.FilteredModels.View.Refresh();
当用户选中一些复选框并将网格发送到编辑模式,然后执行搜索时,我们会收到以下错误
WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction
有没有办法在选中复选框时强制网格退出编辑模式,甚至单击搜索按钮或其他修复方法?
谢谢!
最佳答案
我知道现在回答已经太晚了......但对于正在寻找答案的人来说
按如下顺序使用 cancelEdit 或 commitEdit 方法两次
//用于提交
this.datagrid_layers.CommitEdit();
this.datagrid_layers.CommitEdit();
//取消
this.datagrid_layers.CancelEdit();
this.datagrid_layers.CancelEdit();
关于在 AddNew 或 EditItem 事务 mvvm 期间不允许 WPF DataGrid 'Refresh',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20204592/