zhanglaoshen
2021-09-04 23:38
采纳率: 75%
浏览 97

wpf DocumentViewer datagrid 鼠标悬停图片上报错

值不能为 null。参数名: current
   at System.Windows.LogicalTreeHelper.GetChildren(DependencyObject current)
   at System.Windows.Documents.FixedPage._CreateChildIndex(DependencyObject e)
   at System.Windows.Documents.FixedTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)
   at MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(Point point, Boolean snapToText)
   at MS.Internal.Documents.DocumentPageTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)
   at MS.Internal.Documents.MultiPageTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)
   at MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(Point point, Boolean snapToText)
   at System.Windows.Documents.TextEditorMouse.IsPointWithinInteractiveArea(TextEditor textEditor, Point point)
   at System.Windows.Documents.TextEditorMouse.OnQueryCursor(Object sender, QueryCursorEventArgs e)
   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.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.MouseDevice.UpdateCursorPrivate()
   at System.Windows.Input.MouseDevice.PostProcessInput(Object sender, ProcessInputEventArgs e)
   at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
   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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at WindowsFormsApp1.Program.Main() in C:\Users\ruanbh\Desktop\WindowsFormsApp1\Program.cs:line 18

img

DataTable dt = new DataTable();
dt.Columns.Add("DOCTOR_IMG", typeof(byte[]));
DataRow dr = dt.NewRow();
dr["DOCTOR_IMG"] = File.ReadAllBytes("butterfly.jpg");
dt.Rows.Add(dr);
this.grdGiveDrug.ItemsSource = dt.DefaultView;
<DataGrid Name="grdGiveDrug" HorizontalAlignment="Left" Height="157" Margin="55,83,0,0" VerticalAlignment="Top" Width="334">
            <DataGrid.Columns>
                <!--医生签名-->
                <DataGridTemplateColumn MinWidth="78" Width="*">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <Border ClipToBounds="True" BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Label Content="医生签名" />
                            </Border>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Height="23" Width="70" Source="{Binding Path=DOCTOR_IMG}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


                </DataGrid.Columns>
        </DataGrid>


  • 收藏

2条回答 默认 最新

  • 急速光粒 2021-09-05 08:32
    已采纳

    没有问题啊!我用你的代码运行后,正常显示,鼠标移动上去也没出现异常。你是不是还有什么代码没贴出来。下面是我运行的结果,鼠标悬浮和选择图片没有出现异常。

    img


    我用的vs2015,debug和release都没有出现问题。
    如有问题,可远程看一下。

    1 打赏 评论
    1人已打赏
  • guwei4037 2021-09-05 06:41

    值不能为空,你可以调试下,是不是给的图片路径不对

    打赏 评论

相关推荐 更多相似问题