在 AddNew 或 EditItem 事务 mvvm 期间不允许 WPF DataGrid 'Refresh' [英] WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction mvvm
问题描述
我有以下网格
<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>
然后我有一个 seachCommand 对视图模型中的 collectionViewSource FilteredModels 执行搜索,然后调用
and then i have a seachCommand with performs the search on the collectionViewSource FilteredModels in the viewmodel and then calls
this.FilteredModels.View.Refresh();
当用户选中几个复选框并将网格发送到编辑模式然后执行搜索时,我们会收到以下错误
when a user checks a few of the checkboxes and sends the grid into editmode and then performs a search we get the following error
WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction
有没有办法在复选框被选中或什至在搜索按钮被点击或其他一些修复时强制网格退出编辑模式?
is there a way to force the grid out of edit mode when a check box is checked or maybe even when the seach button is clicked or some other fix for this?
谢谢!
推荐答案
我知道现在回答已经太晚了......但对于正在寻找答案的人
I know its too late to answer...but for someone who is looking for answer
以这样的顺序使用cancelEdit或commitEdit方法两次
use cancelEdit or commitEdit method two times in a sequence like this
//用于提交
this.datagrid_layers.CommitEdit();
this.datagrid_layers.CommitEdit();
//取消
this.datagrid_layers.CancelEdit();
this.datagrid_layers.CancelEdit();
这篇关于在 AddNew 或 EditItem 事务 mvvm 期间不允许 WPF DataGrid 'Refresh'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!