我正在使用Paul McClean所描述的数据虚拟化:http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx
它可以很好地与ListView控件配合使用。
但是当我将它与DataGrid控件(AsyncVirtualizationCollection)一起使用时,它会抛出异常:
“值不能为空,参数名: key”
我不知道原因是什么,也不知道如何阻止它的发生。我需要DataGrid控件的编辑功能
发布于 2011-10-18 05:08:33
你在用字典吗?调试并检查您是否尝试将空值作为键添加到字典中。或者检查您尝试插入的带有空键的网格视图上是否有DataKeyNames参数。
只需在加载/填充数据的地方进行调试(F10/F11)。在Visual Studio中查看“局部变量”窗口。
发布于 2015-06-30 23:03:11
我也遇到过这种情况。原来问题出在VirtualizingCollection (AsyncVirtualizingCollection的基类)中的以下代码:
public T this[int index]
{
// snip
// defensive check in case of async load
if (_pages[pageIndex] == null)
return default(T);
// snip
}如果T是引用类型,则default(T)为null,并且DataGrid不支持null行对象。
为了解决这个问题,我向VirtualizingCollection添加了一个公共属性来保存默认值:
public T DefaultValue = default(T);
并将上面的代码从default(T)改为返回DefaultValue。然后,当我构造AsyncVirtualizingCollection时,我将DefaultValue设置为一个在加载过程中显示的虚拟对象。
发布于 2014-11-14 12:47:17
我发现这个异常实际上是在DataGridItemAttachedStorage类中发生的。这里有一些调用栈框架,希望有人能给我一些关于it.Sorry的线索,关于我糟糕的英语。
mscorlib.dll!System.Collections.Generic.Dictionary<object,System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object>>.FindEntry(object key) 未知
mscorlib.dll!System.Collections.Generic.Dictionary<object,System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object>>.TryGetValue(object key, out System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object> value) 未知
PresentationFramework.dll!System.Windows.Controls.DataGridItemAttachedStorage.TryGetValue(object item, System.Windows.DependencyProperty property, out object value) 未知
PresentationFramework.dll!System.Windows.Controls.DataGridRow.RestoreAttachedItemValue(System.Windows.DependencyObject objectWithProperty, System.Windows.DependencyProperty property) 未知
PresentationFramework.dll!System.Windows.Controls.DataGridRow.SyncProperties(bool forcePrepareCells) 未知
PresentationFramework.dll!System.Windows.Controls.DataGridRow.PrepareRow(object item, System.Windows.Controls.DataGrid owningDataGrid) 未知
PresentationFramework.dll!System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) 未知
PresentationFramework.dll!System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(System.Windows.DependencyObject container, object item) 未知https://stackoverflow.com/questions/7798809
复制相似问题