我需要WPF DataGrid中的一些额外功能,所以我继承它。
我的代码如下所示
public class GenericDataGrid : DataGrid
{
public GenericDataGrid()
{
PreviewMouseMove += GenericDataGrid_PreviewMouseMove;
}
private void GenericDataGrid_PreviewMouseMove(object sender, MouseEventArgs e)
{
if(e == null)
{
Log.Error(this, error);
}
else
{...}
}
}
使用此代码,在我点击网格的随机时间,我收到以下错误:
***System.RuntimeType - System.NullReferenceException: Object reference not set to an instance of an object.
at LBG.PT.Common.View.Core.Controls.Grid.GenericDataGrid.GenericDataGrid_PreviewMouseMove(Object sender, MouseEventArgs e) in c:\BuildAgent2\work\fbe7560eaf130ae\Common\Grid\GenericDataGrid.cs:line 235
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
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.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)***
任何想法,这是否意味着它是控件本身的Bug?如果是这样,我该如何解决这个问题?