【发布时间】:2014-03-04 09:02:39
【问题描述】:
我有一个应用程序在 TabControl 的 tabitems 中显示一些数据网格。在其中部署了它的一台机器上——而且只有一台——切换选项卡会在没有任何警告的情况下使应用程序崩溃。 我无法在那台机器上调试应用程序。我对崩溃的唯一指示来自事件查看器。这是异常堆栈跟踪:
框架版本:v4.0.30319 描述:进程被终止 由于未处理的异常。异常信息: System.NullReferenceException 堆栈:在 System.Windows.Controls.Primitives.DataGridColumnHeader.SetLeftGripperVisibility() 在 System.Windows.Controls.Primitives.DataGridColumnHeader.HookupGripperEvents() 在 System.Windows.FrameworkElement.ApplyTemplate() 在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) 在 System.Windows.UIElement.Measure(System.Windows.Size) 在 System.Windows.Controls.DataGridCellsPanel.MeasureChild(System.Windows.UIElement, System.Windows.Size)在 System.Windows.Controls.DataGridCellsPanel.GenerateChild(System.Windows.Controls.Primitives.IItemContainerGenerator, System.Windows.Size、System.Windows.Controls.DataGridColumn、Int32 ByRef, System.Windows.Size ByRef) 在 System.Windows.Controls.DataGridCellsPanel.GenerateChild(System.Windows.Controls.Primitives.IItemContainerGenerator, System.Windows.Size,System.Windows.Controls.DataGridColumn, System.IDisposable ByRef、Int32 ByRef、System.Windows.Size ByRef)
在 System.Windows.Controls.DataGridCellsPanel.DetermineRealizedColumnsBlockList(System.Windows.Size) 在 System.Windows.Controls.DataGridCellsPanel.MeasureOverride(System.Windows.Size) 在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size) 在 System.Windows.ContextLayoutManager.UpdateLayout() 在 System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object) 在 System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
在 System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object) 在 System.Windows.Media.MediaContext.RenderMessageHandler(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate、System.Object、Int32、System.Delegate)在 System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object,Int32,System.Delegate)在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 System.Threading.ExecutionContext.runTryCode(System.Object) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode,System.Object)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,布尔值)在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)在 System.Windows.Threading.DispatcherOperation.Invoke() 在 System.Windows.Threading.Dispatcher.ProcessQueue() 在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr, MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate、System.Object、Int32、System.Delegate)在 System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object,Int32,System.Delegate)在 System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) 在 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Application.RunInternal(System.Windows.Window) 在 System.Windows.Application.Run() 在 MyApp.App.Main()
这一切都发生在外部代码中。 我尝试从 DataGrid 继承,覆盖 ApplyTemplate 方法并在其中放置一个 try catch。但似乎这是不允许的,由此产生的控制是不可用的。 对于如何解决这个问题,有任何的建议吗? 谢谢
【问题讨论】:
标签: wpf exception datagrid tabcontrol