Skip to content

DataGrid with active focus crashes when being disabled #3054

@MichaeIDietrich

Description

@MichaeIDietrich
  • .NET Core Version: .NET Core 3.1.201
  • Windows version: 19041.264
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

Problem description:

Disabling a DataGrid with active cell focus crashes with an InvalidOperationException.

Actual behavior:

System.InvalidOperationException
 HResult=0x80131509
 Message='NewItemPlaceholderPosition' is not allowed during a transaction begun by 'AddNew'.
 Source=PresentationFramework
 StackTrace:
  at System.Windows.Data.ListCollectionView.set_NewItemPlaceholderPosition(NewItemPlaceholderPosition value)
  at System.Windows.Controls.ItemCollection.System.ComponentModel.IEditableCollectionView.set_NewItemPlaceholderPosition(NewItemPlaceholderPosition value)
  at System.Windows.Controls.DataGrid.UpdateNewItemPlaceholder(Boolean isAddingNewItem)
  at System.Windows.Controls.DataGrid.OnCanUserAddRowsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
  at System.Windows.DependencyObject.CoerceValue(DependencyProperty dp)
  at System.Windows.Controls.DataGrid.OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
  at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
  at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
  at System.Windows.UIElement.set_IsEnabled(Boolean value)
  at DataGridCrash.MainWindow.OnKeyUp(Object sender, KeyEventArgs e) in C:\Users\dddiet\source\repos\DataGridCrash\DataGridCrash\MainWindow.xaml.cs:line 21
  at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
  at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
  at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
  at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
  at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
  at System.Windows.Input.InputManager.ProcessStagingArea()
  at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
  at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
  at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
  at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
  at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
  at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
  at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
  at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
  at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
  at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
  at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
  at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
  at System.Windows.Threading.Dispatcher.Run()
  at System.Windows.Application.RunDispatcher(Object ignore)
  at System.Windows.Application.RunInternal(Window window)
  at System.Windows.Application.Run()
  at DataGridCrash.App.Main()

Expected behavior:

When a DataGrid with active cell focus is disabled, the focus should normally traverse to the next focusable element.

Minimal repro:

  1. Check out this minimal repro: https://github.com/MichaeIDietrich/DataGridCrash
  2. Start the application
  3. Set focus into the first cell (cell is now in edit mode)
  4. Press F1 key (F1 is hooked to disable the DataGrid)

Use case:

We use the F1 hotkey to show an overlay (same window) to the user at any point in the application and disable the current content, which is being faded out as long as the overlay is in the foreground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugProduct bug (most likely)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions