2011-01-31 40 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> 
相關問題