I have prepared a sample that shows you how to hook up your ObservableCollection to your DataGridVirtualizingCollectionViewSource. This is as basic as it gets, but the main difference between the BindingList<T> and an ObservableCollection is that you will need to use the Skip() and Take() methods to get the range of values and copy them to the Object array. Please see the following:
C#
---------
public partial class MainWindow : Window
{
ObservableCollection<DataObject> data = new
ObservableCollection<DataObject>();
public MainWindow()
{
InitializeComponent();
data.Add(new DataObject() { Name = "A", Value = 2 });
data.Add(new DataObject() { Name = "R", Value = 1 });
data.Add(new DataObject() { Name = "Q", Value = 5 });
data.Add(new DataObject() { Name = "S", Value = 2 });
data.Add(new DataObject() { Name = "M", Value = 2 });
}
private void
DataGridVirtualizingCollectionViewSource_QueryItemCount(object sender,
Xceed.Wpf.DataGrid.QueryItemCountEventArgs e)
{
e.Count = data.Count;
}
private void DataGridVirtualizingCollectionViewSource_QueryItems(object sender, Xceed.Wpf.DataGrid.QueryItemsEventArgs e)
{
ObservableCollection<DataObject> tempData = new ObservableCollection<DataObject>(data);
DataObject[] dataArray = tempData.Skip(e.AsyncQueryInfo.StartIndex).Take(e.AsyncQueryInfo.RequestedItemCount).ToArray();
e.AsyncQueryInfo.EndQuery(dataArray);
}
private ObservableCollection<DataObject> GetData(DataGridVirtualizingCollectionView dgvcv)
{
return new ObservableCollection<DataObject>(data);
}
}
---------
Visual Basic.NET
---------
Public Partial Class MainWindow
Inherits Window
Private data As New ObservableCollection(Of DataObject)()
Public Sub New()
InitializeComponent()
data.Add(New DataObject() With { _
Key .Name = "A", _
Key .Value = 2 _
})
data.Add(New DataObject() With { _
Key .Name = "R", _
Key .Value = 1 _
})
data.Add(New DataObject() With { _
Key .Name = "Q", _
Key .Value = 5 _
})
data.Add(New DataObject() With { _
Key .Name = "S", _
Key .Value = 2 _
})
data.Add(New DataObject() With { _
Key .Name = "M", _
Key .Value = 2 _
})
End Sub
Private Sub DataGridVirtualizingCollectionViewSource_QueryItemCount(sender As Object, e As Xceed.Wpf.DataGrid.QueryItemCountEventArgs)
e.Count = data.Count
End Sub
Private Sub DataGridVirtualizingCollectionViewSource_QueryItems(sender As Object, e As Xceed.Wpf.DataGrid.QueryItemsEventArgs)
Dim tempData As New ObservableCollection(Of DataObject)(data)
Dim dataArray As DataObject() = tempData.Skip(e.AsyncQueryInfo.StartIndex).Take(e.AsyncQueryInfo.RequestedItemCount).ToArray()
e.AsyncQueryInfo.EndQuery(dataArray)
End Sub
Private Function GetData(dgvcv As DataGridVirtualizingCollectionView) As ObservableCollection(Of DataObject)
Return New ObservableCollection(Of DataObject)(data)
End Function
End Class
---------
Marc
Developer in Technical Support
Xceed - Multi-talented components - http://xceed.com