nullReferenceExceptionプロパティをXCeedDatagridのボタンにバインドするとき
-
27-10-2019 - |
質問
これは私を夢中にさせています。この問題は、Datagridがスクロールバーを必要とするのに十分な大きさである場合にのみ表示されるため、データの仮想化がこれに手をかけることを強くお勧めします。このDatagridで定義された最後の列の下のXAMLからわかるように、その可視性がコントロールのデータソースであるDatagridCollectionViewのブールの「エラープレゼント」プロパティにバインドされているボタンがあります。何らかの理由で、私には知られていない、大きなデータセットが制御にロードされると、すべてのプロパティにヌル値があるいくつかの空の行があります。最後の列にコメントすると、グリッドとそのデータが適切に表示されますが、行のデータが実際に処理されると(コンバーターのように)、プレゼンテーションフレームワークでこの厄介なエラーが発生します。すべてを含めて申し訳ありませんが、すべてのWindowsコードを示したいと思います。
'apreii.vshost.exe'(Managed(v4.0.30319)):loaded 'c: windows microsoft.net assembly gac_msil accessibility v4.0_4.0.0.0.0__b03f5ff7f11d50a3a accessibility.dll' transactions clatival: 0:http://msdn.microsoft.com/tracecodes/system/activitytracing/2004/07/reliability/exception/unhandledunhandledlededlededlededledlededlededlededexception、mscorlib、version = 4.0.0参照はオブジェクトのインスタンスに設定されていません。 System.Windows.Data.BindingExpression.TransferValue(Object NewValue、Boolean IsaSubPropertyChange)at System.Windows.Data.BindingExpression.Activate(Object Item)at System.Windows.Data.BindingExpression.AttachToContext(AttachTachToContext(AttachTachtemptext)at System.Windows。 data.bindingExpression.ms.data.data.idatabindengineclient.attachtocontext(boolean lastCance)Ms.Internal.data.databindengine.task.run(boolean lastchance)mssenternal.data.databindengine.run(Object arg)at ms。 internal.data.databindengine.onlayoutupdated(object sender、eventargs e)at System.windows.contextlayoutmanager.firelayoutupdateevent()at System.windows.contextLayoutManager.updateLayout()at System.Windows.ContextLayOutDageRager.UpdageRager.UpdageRager System.windows.media.mediacontext.rendermessagehandlercore(object resizedCompositionTarget)のSystem.Windows.MediaContext.RenderMessageHandler(Object ResizedCompositionTarget)のSystem.Windows.MediaContext.RenderMessageHandlercore(Object ResizedCompositionTarget)のsystem.windows.mediaTontext.RenderMessageHandlercoreで、MediaContext.fireInvokeonRenderCallbacks() System.windows.threading.exceptionwrapper.internalRealcall(Delegate Callback、object args、int32 numargs)Ms.ternal.threading.exceptionfilterhelper.trycatch(オブジェクトソース、オブジェクトメソッド、オブジェクトargs、int32 numargs、delegate catchhandler)。 threading.dispatcher.wrappingInvoke(デリゲートコールバック、オブジェクトArgs、int32 numargs、delegate catchhandler)at system.windows.threading.dispatcheroperation.invokeimpl()at system.threading.executioncontext.runtrycode(object userdata) .ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state )System.windows.threading.dispatcheroperation.invoke()at System.windows.threading.dispatcher.processqueue ()System.Windows.threading.dispatcher.wndprochook(intptr hwnd、int32 msg、intptr wparam、intptr lparam、boolean&handled)でms.win32.hwndwrapper.wndproc(intptr hwnd、int32 msg、intptr&wolm、intptr hmm、intptr hmm、intptr hmm、intptr Handled)Ms.Win32.hwndsubclass.dispatchercallbackoperation(object o)at System.Windows.ThectionWrapper.InternalRealCall(Delegate Callback、Object Args、Int32 Numargs) 、Object Args、int32 numargs、Delegate Catchhandler)at System.Windows.threading.dispatcher.wrappingInvoke(Delegate Callback、Object Args、Int32 Numargs、Delegate Catchhandler)at System.Windows.Thispatcher.Invokeimpl Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatche system.windows.application.runinternal(ウィンドウウィンドウ)のsystem.windows.application.run()のsystem.windows.applame.runternal()のr.pushframeimpl(dispatcherframeフレーム)aprei.app.main()in d: tfs hermes dev hermes5.05 src uiservices apreii obj debug app.g.cs:system.appdomain._nexecuteassembly(runtimeassemblyアセンブリ、string [] args)at system.runtime.hosting.applicationactivator.createInstance(activation -context activation context、string、system.applicationactivator.createinstance ] activationcustomdata)at microsoft.visualstudio.hostingprocess.hostproc.runusersemblydebuginzone()at System.threading.executionContext.run 、object state)at System.threading.threadhelper.threadstart()System.NullReferenceException:オブジェクト参照はオブジェクトのインスタンスに設定されていません。 System.Windows.Data.BindingExpression.TransferValue(Object NewValue、Boolean IsaSubPropertyChange)at System.Windows.Data.BindingExpression.Activate(Object Item)at System.Windows.Data.BindingExpression.AttachToContext(AttachTachToContext(AttachTachtemptext)at System.Windows。 data.bindingExpression.ms.data.data.idatabindengineclient.attachtocontext(boolean lastCance)Ms.Internal.data.databindengine.task.run(boolean lastchance)mssenternal.data.databindengine.run(Object arg)at ms。 internal.data.databindengine.onlayoutupdated(object sender、eventargs e)at System.windows.contextlayoutmanager.firelayoutupdateevent()at System.windows.contextLayoutManager.updateLayout()at System.Windows.ContextLayOutDageRager.UpdageRager.UpdageRager System.windows.media.mediacontext.rendermessagehandlercore(object resizedCompositionTarget)のSystem.Windows.MediaContext.RenderMessageHandler(Object ResizedCompositionTarget)のSystem.Windows.MediaContext.RenderMessageHandlercore(Object ResizedCompositionTarget)のsystem.windows.mediaTontext.RenderMessageHandlercoreで、MediaContext.fireInvokeonRenderCallbacks() System.windows.threading.exceptionwrapper.internalRealcall(Delegate Callback、object args、int32 numargs)Ms.ternal.threading.exceptionfilterhelper.trycatch(オブジェクトソース、オブジェクトメソッド、オブジェクトargs、int32 numargs、delegate catchhandler)。 threading.dispatcher.wrappingInvoke(デリゲートコールバック、オブジェクトArgs、int32 numargs、delegate catchhandler)at system.windows.threading.dispatcheroperation.invokeimpl()at system.threading.executioncontext.runtrycode(object userdata) .ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state )System.windows.threading.dispatcheroperation.invoke()at System.windows.threading.dispatcher.processqueue ()System.Windows.threading.dispatcher.wndprochook(intptr hwnd、int32 msg、intptr wparam、intptr lparam、boolean&handled)でms.win32.hwndwrapper.wndproc(intptr hwnd、int32 msg、intptr&wolm、intptr hmm、intptr hmm、intptr hmm、intptr Handled)Ms.Win32.hwndsubclass.dispatchercallbackoperation(object o)at System.Windows.ThectionWrapper.InternalRealCall(Delegate Callback、Object Args、Int32 Numargs) 、Object Args、int32 numargs、Delegate Catchhandler)at System.Windows.threading.dispatcher.wrappingInvoke(Delegate Callback、Object Args、Int32 Numargs、Delegate Catchhandler)at System.Windows.Thispatcher.Invokeimpl Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatche system.windows.application.runinternal(ウィンドウウィンドウ)のsystem.windows.application.run()のsystem.windows.applame.runternal()のr.pushframeimpl(dispatcherframeフレーム)aprei.app.main()in d: tfs hermes dev hermes5.05 src uiservices apreii obj debug app.g.cs:system.appdomain._nexecuteassembly(runtimeassemblyアセンブリ、string [] args)at system.runtime.hosting.applicationactivator.createInstance(activation -context activation context、string、system.applicationactivator.createinstance ] activationcustomdata)at microsoft.visualstudio.hostingprocess.hostproc.runusersemblydebuginzone()at System.threading.executionContext.run 、オブジェクト状態)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);
}
助けてくれてありがとう。これらのnullレコード(基礎となるデータセットとDatagridCollectionViewにない)をCellContentTentTemplateの可視性コンバーターによって処理しないようにする方法のデータ仮想化(それが問題の場合)を適切にオフにする方法がわかりません。
解決
私は1日後に自分の質問に答えるのが嫌いですが、ここにいます。はぁ。コンバーターコール用のXAMLでは、先祖Datarowを取得していましたが、それをいくつかのXCEECTドキュメントから引き出しました。私の推測では、元のエラーは、別のスレッドでの仮想化でいくつかの作業が行われたことから生じていたため、私のコードのいずれかを指すスタックトレースが不足しています。
これは機能します:
<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>