顾名思义,滚动时应用程序崩溃。我添加了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>
答案 0 :(得分:0)
通过在VirtualizingPanel.IsVirtualizing="False"
XAML标记中添加<DataGrid>
来解决问题