2011-01-31 80 views
0

这是一个让我疯狂的问题。这个问题仅在数据网格足够大以至于需要滚动条时才会显示,所以我强烈建议数据虚拟化在这方面起作用。正如你可以从xaml下面看到,为这个数据网格定义的最后一列是一个按钮,它的可见性绑定到DataGridCollectionView上的布尔型“ErrorsPresent”属性,该属性是控件的数据源。 出于某种原因,我不知道,当一个大数据集被加载到控件中时,有一些空行,每个属性都有空值。如果我注释掉最后一列,网格及其数据将正确显示,但是当行数据实际处理完毕(如转换器中)时,我会在PresentationFramework中看到这个令人讨厌的错误。我很抱歉包含这一切,但我想证明它的所有Windows代码:将属性绑定到Xceed Datagrid中的按钮时出现NullReferenceException

'APreII.vshost.exe'(Managed(v4.0.30319)):Loaded'C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ Accessibility \ v4.0_4.0.0.0__b03f5f7f11d50a3a \ Accessibility.dll' System.Transactions Critical:0:http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionAPreII.vshost.exeSystem.NullReferenceException,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089Object未设置为对象实例的引用。在System.Windows.Data.BindingExpression.TransferValue在System.Windows.Data.BindingExpression.Activate(对象项) (对象NEWVALUE,布尔isASubPropertyChange) 在System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt尝试) 在系统.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Run(Object ARG) 在MS.Internal.Data.DataBindEngine.OnLayoutUpdated(对象发件人,EventArgs的) 在System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() 在System.Windows.ContextLayoutManager.UpdateLayout() 在System.Windows.ContextLayoutManager。 ü pdateLayoutCallback(对象ARG) 在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 在System.Windows.Media.MediaContext.RenderMessageHandlerCore(对象resizedCompositionTarget) 在System.Windows.Media.MediaContext.RenderMessageHandler(对象resizedCompositionTarget) 在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) at System。 Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象args,Int32 numArgs,委托catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.Exe在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx)上的System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,Object userData) (对象userData) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态) 在System.Windows.Threading.DispatcherOperation.Invoke() 在System.Windows.Threading.Dispatcher.ProcessQueue() 在System.Windows .Threading.Dispatcher.WndProcHook(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean & amp;处理) 在MS.Win32.HwndWrapper.WndProc(IntPtr的HWND,MSG的Int32,IntPtr的wParam中,IntPtr的lParam的,布尔&安培;处理) 在MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象O) 在System.Windows.Threading程序.ExceptionWrapper。InternalRealCall(代表回调,对象参数,Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate method,Object args,Int32 numArgs,Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke代理回调,Object args,Int32 numArgs,Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate method,Object args,Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr HWND,MSG的Int32,IntPtr的wParam中,IntPtr的LPARAM) 在MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG &安培; MSG) 在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame帧) 在System.Windows.Application。 RunInter在D:\ tfs \ Hermes \ dev \ Hermes5.0 \ src \ UIServices \ APreII \ obj \ Debug \ App中,在System.Windows.Application.Run()处的APreII.App.Main()处打开nal(窗口窗口) .g.cs:线0 在System.AppDomain._nExecuteAssembly(RuntimeAssembly组件,字串[] args) 在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext,字符串[] activationCustomData)在Microsoft.VisualStudio.HostingProcess .HostProc.RunUsersAssemblyDebugInZone() 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态,布尔ignoreSyncCtx) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态) 在系统.Threading.ThreadHelper.ThreadStart( )System.NullReferenceException:未将对象引用设置为对象的实例。 在System.Windows.Data.BindingExpression.TransferValue(对象NEWVALUE,布尔isASubPropertyChange) 在System.Windows.Data.BindingExpression.Activate(对象项) 在System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt尝试) 在System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Run(在MS.Internal.Data.DataBindEngine.OnLayoutUpdated(对象发送者,EventArgs的) 对象ARG) 在System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() 在System.Windows.ContextLayoutManager.UpdateLayout() 在SYSTE m.Windows.ContextLayoutManager.UpdateLayoutCallback(对象ARG) 在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 在System.Windows.Media.MediaContext.RenderMessageHandlerCore(对象resizedCompositionTarget) 在System.Windows.Media.MediaContext.RenderMessageHandler (Object resizedCompositionTarget) 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) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback,Object args,Int32 numArgs,Delegate catchHandler)在System.Windows.Threading.DispatcherOperation.InvokeImpl() 在System.Threading.ExecutionContext.runTryCode(对象的UserData) 在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,对象的UserData) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态) 在System.Windows.Threading.DispatcherOperation.Invoke() 在System.Windows.Threading.Dispatcher.ProcessQueue( ) 在System.Windows.Threading.Dispatcher。WndProcHook(IntPtr的HWND,MSG的Int32,IntPtr的wParam中,IntPtr的lParam的,布尔&安培;处理) 在MS.Win32.HwndWrapper.WndProc(IntPtr的HWND,MSG的Int32,IntPtr的wParam中,IntPtr的lParam的,布尔&安培;处理) 在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,对象参数,Int32 numArgs,Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback,Object args,Int32 numArgs,Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority,TimeSpan timeout ,代表我(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG & amp; MSG) 在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame帧) 在System.Windows.Application.RunInternal(窗口窗口) 在System.Windows.Application.Run() 在APreII.App.Main()在D:\ tfs \ Hermes \ dev \ Hermes5.0 \ src \ UIServices \ APreII \ obj \ Debug \ App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext,字符串[] activationCustomData) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态, Boolean ignoreSyncCtx) at System。 Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state) at System.Threading.ThreadHelper.ThreadStart()

Xaml。正如你所看到的,我已经通过设置CanContentScroll & ItemScrollingBehavior属性来禁用虚拟化,这没有任何作用。 :

   <XceedDG:DataGridControl Grid.Column="2" x:Name="EncounterDataGrid" ItemsSource="{Binding Path = EncounterDataGridCollectionView, UpdateSourceTrigger=PropertyChanged}" 
            Background="{x:Static Views:DataGridControlBackgroundBrushes.ElementalBlue}" CellErrorStyle="{StaticResource cell_error}" 
            FontSize="12" AutoCreateColumns="False" ItemScrollingBehavior="Immediate" ScrollViewer.CanContentScroll="False" 
            EditTriggers="None" NavigationBehavior="RowOnly" CellEditorDisplayConditions="None" > 

       <XceedDG:DataGridControl.View> 
        <Views:TableView ColumnStretchMode="All" ShowRowSelectorPane="False" ScrollViewer.CanContentScroll="False" 
        ColumnStretchMinWidth="100"/> 
       </XceedDG:DataGridControl.View> 
       <!--Group Header formatting--> 
       <XceedDG:DataGridControl.Resources> 
        <DataTemplate DataType="{x:Type XceedDG:Group}"> 
         <TextBlock Foreground="DarkSlateBlue" 
         Padding="3,3,3,3" VerticalAlignment="Center" 
         FontSize="14" FontWeight="Black" MaxWidth="850" TextWrapping="Wrap" 
         Text="{Binding Path=., Converter={StaticResource GroupHeaderTextConverterType}}"/> 
        </DataTemplate> 
       </XceedDG:DataGridControl.Resources> 
       <!--Visible column definitions--> 
       <XceedDG:DataGridControl.Columns> 
        <XceedDG:Column MinWidth="50" 
        FieldName="AccountNumber" 
        Title="Account #" 
        IsMainColumn="True" 
        ShowInColumnChooser="False" 
        TextWrapping="Wrap" 
        ReadOnly="True" 
        Visible="True"/> 
        <XceedDG:Column MinWidth="50" 
        FieldName="DOB" 
        Title="Date of Birth" 
        IsMainColumn="False" 
        ShowInColumnChooser="False" 
        TextWrapping="Wrap" 
        ReadOnly="True" 
        Visible="True"/> 

        <XceedDG:Column MinWidth="4" 
        FieldName="Processed" 
        Title="Processed" 
        IsMainColumn="False" 
        ShowInColumnChooser="False" 
        TextWrapping="Wrap" 
        ReadOnly="True" 
        Visible="True"/> 
        <XceedDG:Column MinWidth="25" 
        FieldName="ErrorsPresent" 
        Title="Errors" 
        IsMainColumn="False" 
        ShowInColumnChooser="False" 
        TextWrapping="Wrap" 
        ReadOnly="True" 
        Visible="True" > 
        <XceedDG:Column.CellContentTemplate> 
         <DataTemplate> 
          <Button Command="{StaticResource ShowErrorDialogCommand}" CommandParameter="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type XceedDG:DataRow}}}" Foreground="Red" 
          Content="View Errors" FontSize="11" 
          Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type XceedDG:DataRow}}, Converter={StaticResource VisibilityConverterBooleanDataRow}, ConverterParameter=ErrorsPresent}"/> 
         </DataTemplate> 
        </XceedDG:Column.CellContentTemplate> 

        </XceedDG:Column> 

       </XceedDG:DataGridControl.Columns> 
      </XceedDG:DataGridControl> 

和公正的笑声,我是如何使DataGridCollectionView:

 private void CreateDataGridCollectionView() 
    { 
     EncounterDataGridCollectionView = new DataGridCollectionView(Encounters); 
     EncounterDataGridCollectionView.Filter = new Predicate<object>(IsIncludedPt); 
     //Group by unit 
     PropertyGroupDescription groupDescription = new PropertyGroupDescription("UnitID"); 
     EncounterDataGridCollectionView.GroupDescriptions.Add(groupDescription); 
    } 

感谢您的帮助。我只是不知道如何正确关闭数据虚拟化(如果这是问题),如何让这些空记录(不在底层数据集和DataGridCollectionView中)由CellContentTemplate可见性转换器处理。

回答

0

我讨厌回答我自己的问题1天后,但我们在这里。叹。 尽管在我的转换器调用的XAML中,我得到的祖先数据行是从一些Xceed文档中提取的,但仅向转换器发送了我关心的属性(只是'绑定')似乎可行。 我的猜测是,原来的错误是由于在另一个线程上进行虚拟化而导致的一些工作,因此缺少指向我的任何代码的堆栈跟踪。

这工作:

     <XceedDG:Column MinWidth="25" 
        FieldName="ErrorsPresent" 
        Title="Errors" 
        IsMainColumn="False" 
        ShowInColumnChooser="False" 
        TextWrapping="Wrap" 
        ReadOnly="True" 
        Visible="True" > 
        <XceedDG:Column.CellContentTemplate> 
         <DataTemplate> 
          <Button Command="{StaticResource ShowErrorDialogCommand}" CommandParameter="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type XceedDG:DataRow}}}" Foreground="Red" 
            Content="View Errors" FontSize="11" 
            Visibility="{Binding Converter={StaticResource VisibilityConverterBooleanDataRow}}" /> 
          </DataTemplate> 
        </XceedDG:Column.CellContentTemplate> 
相关问题