2

我有一个数据网格,其中我使用绑定到整数属性的 TextColumn。我可以编辑 TextColumn 中的值,直到单击列标题。单击时该列将正确排序,但是当我随后尝试编辑一个值时,当我通过单击其他地方导致 LostFocus 事件时,我得到一个异常。

(问题更改为所需的最低设置以使其可重现)

XAML:

<DataGridTextColumn Binding="{Binding CompStrength}"/>

堆栈跟踪:

bij System.Windows.Controls.DataGrid.UpdateRowEditing(DataGridCell cell)
bij System.Windows.Controls.DataGrid.OnExecutedCommitEdit(ExecutedRoutedEventArgs e)
bij System.Windows.Controls.DataGrid.OnExecutedCommitEdit(Object sender, ExecutedRoutedEventArgs e)
bij System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
bij System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
bij System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
bij System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
bij System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
bij System.Windows.UIElement.OnExecutedThunk(Object sender, ExecutedRoutedEventArgs e)
bij System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
bij System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
bij System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
bij System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bij System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bij System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
bij System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated)
bij System.Windows.Input.RoutedCommand.Execute(Object parameter, IInputElement target)
bij System.Windows.Controls.DataGrid.EndEdit(RoutedCommand command, DataGridCell cellContainer, DataGridEditingUnit editingUnit, Boolean exitEditMode)
bij System.Windows.Controls.DataGrid.OnCurrentCellChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
bij System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bij System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bij System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
bij System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
bij System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
bij System.Windows.DependencyObject.SetCurrentValueInternal(DependencyProperty dp, Object value)
bij System.Windows.Controls.DataGrid.set_CurrentCellContainer(DataGridCell value)
bij System.Windows.Controls.DataGrid.set_FocusedCell(DataGridCell value)
bij System.Windows.Controls.DataGridCell.OnAnyGotFocus(Object sender, RoutedEventArgs e)
bij System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
bij System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bij System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bij System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
bij System.Windows.FrameworkElement.OnGotFocus(RoutedEventArgs e)
4

2 回答 2

2

在煞费苦心地重建项目后,我终于找到了这个异常的原因:令人惊讶的是,在将 PresentationFramework.Classic.dll 中的 classc.xaml 主题作为资源添加到 WPF 项目后出现了错误。我就此事联系了微软,我们会看看会发生什么......

于 2012-07-11T20:11:20.737 回答
0

实际上,我发现我自己的问题是来自 CellEditEnding 事件处理程序的回调试图更新网格数据源,这导致了该行为。添加标志以通知网格正在更新解决了我的问题

于 2019-09-19T15:01:15.687 回答