WPF DataGrid ContextMenu导致应用程序崩溃

时间:2018-09-05 07:19:21

标签: wpf datagrid contextmenu .net-4.5

我有一个WPF DataGrid.ContextMenu XAML定义,如下所示:

<DataGrid.ContextMenu>
    <ContextMenu >
        <MenuItem x:Name="mChangeVessel" Header="Change Vessel" />
        <MenuItem x:Name="mChangeVoyage" Header="Change Voyage" />
    </ContextMenu>
</DataGrid.ContextMenu>

VB处理程序:

Private Sub mChangeVessel_Click(sender As Object, e As RoutedEventArgs) Handles mChangeVessel.Click
    Try
        MessageBox.Show("Vessel Changed", "Test Message", MessageBoxButton.OK, MessageBoxImage.Information)
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error)
    End Try
End Sub

Private Sub mChangeVoyage_Click(sender As Object, e As RoutedEventArgs) Handles mChangeVoyage.Click
    Try
        MessageBox.Show("Voyage Changed", "Test Message", MessageBoxButton.OK, MessageBoxImage.Information)
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error)
    End Try
End Sub

在5台PC中,有4台我运行了我的应用程序,它运行正常。在我的笔记本电脑上(我已经对我的应用程序进行了广泛的测试,直到现在还没有出现问题),当我右键单击数据网格时,我的应用程序就死了。您可以看到我试图添加一些错误处理,但是没有被发现。

我觉得这是一个.NET框架依赖性问题,但在我看来,所有机器都具有最新版本(4.7 ish)。

我应该针对其他.NET Framework版本吗?我的目标是4.5 .NET“客户端配置文件”有哪些版本?

如果这些.NET Framework问题使错误的树陷入困境,那么谁能建议我该如何调试此问题?我的笔记本电脑上没有Visual Studio。

编辑:

我已经从Windows应用程序事件日志中添加了例外。谁能指出我正确的方向来解决这个问题?我想进行依赖性检查,以确保我的目标计算机具有所有必需的库。最好的方法是什么?

错误:

Application: WinnipegWpf.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Windows.Automation.Peers.DataGridItemAutomationPeer..ctor(System.Object, System.Windows.Automation.Peers.DataGridAutomationPeer)
   at System.Windows.Automation.Peers.DataGridAutomationPeer.CreateItemAutomationPeer(System.Object)
   at System.Windows.Automation.Peers.ItemsControlAutomationPeer.FindOrCreateItemAutomationPeer(System.Object)
   at System.Windows.Automation.Peers.DataGridAutomationPeer.RaiseAutomationSelectionEvents(System.Windows.Controls.SelectionChangedEventArgs)
   at System.Windows.Controls.DataGrid.OnSelectionChanged(System.Windows.Controls.SelectionChangedEventArgs)
   at System.Windows.Controls.Primitives.Selector+SelectionChanger.End()
   at System.Windows.Controls.DataGrid.MakeFullRowSelection(ItemInfo, Boolean, Boolean)
   at System.Windows.Controls.DataGrid.HandleSelectionForCellInput(System.Windows.Controls.DataGridCell, Boolean, Boolean, Boolean)
   at System.Windows.Controls.DataGrid.OnContextMenuOpening(System.Windows.Controls.ContextMenuEventArgs)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.PopupControlService.RaiseContextMenuOpeningEvent(System.Windows.IInputElement, Double, Double, Boolean)
   at System.Windows.Controls.PopupControlService.ProcessMouseUp(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Controls.PopupControlService.OnPostProcessInput(System.Object, System.Windows.Input.ProcessInputEventArgs)
   at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(System.Windows.Input.ProcessInputEventHandler, System.Windows.Input.ProcessInputEventArgs)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at WinnipegWpf.Application.Main()

0 个答案:

没有答案