Как видно из заголовка, приложение падает при прокрутке. Я добавил события MouseWheel
и PreviewMouseWheel
для обработки прокрутки в столбце, но некоторые все еще справляются.
Определенную строку нельзя отследить, но я думаю, что это может быть связано со следующим кодом:
TextBox ValueCell = (TextBox)sender;
if (GRID.SelectedItem == null || ValueCell == null || GRID.SelectedIndex <= 0) return;
//Obtain the new value
string Value = ValueCell.Text;
//Obtain the item ID
DataGridRow Row = (DataGridRow)GRID.ItemContainerGenerator.ContainerFromIndex(GRID.SelectedIndex);
if (Row == null) return;
DataGridCell RowColumn = GRID.Columns[0].GetCellContent(Row).Parent as DataGridCell;
Не так много информации, кроме:
PresentationFramework.dll! System.Windows.Controls.DataGridRow.RestoreAttachedItemValue (свойство System.Windows.DependencyObject objectWithProperty, System.Windows.DependencyProperty) Загружены неизвестные символы.
Стеки вызовов:
PresentationFramework.dll!System.Windows.Controls.DataGridRow.RestoreAttachedItemValue(System.Windows.DependencyObject objectWithProperty, System.Windows.DependencyProperty property) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.DataGridRow.SyncProperties(bool forcePrepareCells) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.DataGridRow.PrepareRow(object item, System.Windows.Controls.DataGrid owningDataGrid) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(System.Windows.DependencyObject container, object item) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(System.Windows.DependencyObject container) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.InsertContainer(int childIndex, System.Windows.UIElement container, bool isRecycled) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(int childIndex, System.Windows.UIElement child, bool newlyRealized, bool isBeforeViewport) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureChild(ref System.Windows.Controls.Primitives.IItemContainerGenerator generator, ref System.Windows.Controls.Primitives.IContainItemStorage itemStorageProvider, ref System.Windows.Controls.Primitives.IContainItemStorage parentItemStorageProvider, ref object parentItem, ref bool hasUniformOrAverageContainerSizeBeenSet, ref double computedUniformOrAverageContainerSize, ref double computedUniformOrAverageContainerPixelSize, ref bool computedAreContainersUniformlySized, ref bool hasAnyContainerSpanChanged, ref System.Collections.IList items, ref object item, ref System.Collections.IList children, ref int childIndex, ref bool visualOrderChanged, ref bool isHorizontal, ref System.Windows.Size childConstraint, ref System.Windows.Rect viewport, ref System.Windows.Controls.VirtualizationCacheLength cacheSize, ref System.Windows.Controls.VirtualizationCacheLengthUnit cacheUnit, ref bool foundFirstItemInViewport, ref double firstItemInViewportOffset, ref System.Windows.Size stackPixelSize, ref System.Windows.Size stackPixelSizeInViewport, ref System.Windows.Size stackPixelSizeInCacheBeforeViewport, ref System.Windows.Size stackPixelSizeInCacheAfterViewport, ref System.Windows.Size stackLogicalSize, ref System.Windows.Size stackLogicalSizeInViewport, ref System.Windows.Size stackLogicalSizeInCacheBeforeViewport, ref System.Windows.Size stackLogicalSizeInCacheAfterViewport, ref bool mustDisableVirtualization, bool isBeforeFirstItem, bool isAfterFirstItem, bool isAfterLastItem, bool skipActualMeasure, bool skipGeneration, ref bool hasBringIntoViewContainerBeenMeasured, ref bool hasVirtualizingChildren) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(System.Windows.Size constraint, ref double? lastPageSafeOffset, ref System.Collections.Generic.List<double> previouslyMeasuredOffsets, ref double? lastPagePixelSize, bool remeasure) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(System.Windows.Size constraint) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) Unknown Symbols loaded.
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) Unknown Symbols loaded.
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Unknown Symbols loaded.
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) Unknown Symbols loaded.
PresentationCore.dll!System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() Unknown Symbols loaded.
PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() Unknown Symbols loaded.
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) Unknown Symbols loaded.
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Unknown Symbols loaded.
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Unknown Symbols loaded.
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 954 C# Symbols loaded.
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 902 C# Symbols loaded.
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 891 C# Symbols loaded.
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown Symbols loaded.
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown Symbols loaded.
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown Symbols loaded.
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown Symbols loaded.
[Native to Managed Transition] Annotated Frame
[Managed to Native Transition] Annotated Frame
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown Symbols loaded.
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) Unknown Symbols loaded.
PresentationFramework.dll!System.Windows.Application.Run() Unknown Symbols loaded.
App.Main() Unknown Symbols loaded.
РЕДАКТИРОВАТЬ: Вот сообщение Исключено:
Exception thrown: 'System.NullReferenceException' in PresentationFramework.dll An unhandled exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll Object reference not set to an instance of an object.
EDIT2: Приведенный выше код вложен в TextBox LostFocus
событие
EDIT3: Вот мой XAML-код для сетки:
<DataGrid x:Name="GRID" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False"
AutoGenerateColumns="False" Grid.Row="1" Grid.Column="1" Margin="5" AllowDrop="True"
Drop="GRID_Drop" Grid.ColumnSpan="3" CellEditEnding="GRID_CellEditEnding" >
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
<DataGridTextColumn x:Name="IdCol" Header="ID" IsReadOnly="True"
Binding="{Binding ItemId}" />
<DataGridTextColumn x:Name="HexIdCol" Header="Hex ID" IsReadOnly="True"
Binding="{Binding HexId}" />
<DataGridTextColumn x:Name="ItemCol" Header="Item" IsReadOnly="True"
Binding="{Binding ItemNameFormatted}" />
<DataGridComboBoxColumn x:Name="VCol" Header="V"
SelectedItemBinding="{Binding Path=V, NotifyOnTargetUpdated=True}"
DisplayMemberPath="{Binding Path=V}"/>
<DataGridTemplateColumn x:Name="Va" Header="Va">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid MouseWheel="Grid_MouseWheel" PreviewMouseWheel="Grid_PreviewMouseWheel">
<TextBox x:Name="VaTextBox"
Text="{Binding Data, Mode=TwoWay, NotifyOnSourceUpdated=True}"
LostFocus="VaTextBox_LostFocus">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Options}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<ComboBox x:Name="VaComboBox" ItemsSource="{Binding Options}"
SelectedItem="{Binding Data, Mode=TwoWay, NotifyOnSourceUpdated=True}"
SelectionChanged="VaComboBox_SelectionChanged">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Options}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn x:Name="RaCol" Header="Ra"
Binding="{Binding Ra, NotifyOnTargetUpdated=True}" />
</DataGrid.Columns>
</DataGrid>