问题
Anyone can share the code for the DomainCollectionView in VB.NET? I have an error, Argument not specified for parameter 'op' of 'Private Sub OnLoadProductPMListCompleted(op As System.ServiceModel.DomainServices.Client.LoadOperation(Of ProductPM))'.
Public Sub New()
InitializeComponent()
Dim collectionViewLoader As DomainCollectionViewLoader(Of ProductPM)
collectionViewLoader = New DomainCollectionViewLoader(Of ProductPM)(Function() Me.LoadProductPMList(), Me.OnLoadProductPMListCompleted)
ProductCollectionView = New DomainCollectionView(collectionViewLoader, Products)
ProductCollectionView.Refresh()
Me.ProductListBox.ItemsSource = ProductCollectionView
End Sub
Public Function LoadProductPMList() As LoadOperation(Of ProductPM)
Dim qry As EntityQuery(Of ProductPM) = context.GetProductsQuery
Return context.Load(qry)
End Function
Private Sub OnLoadProductPMListCompleted(op As LoadOperation(Of ProductPM))
If op.HasError = True Then
ElseIf op.IsCanceled = False Then
CType(Products, EntityList(Of ProductPM)).Source = op.Entities
End If
End Sub
回答1:
Sorry for the late reply, I have been busy. I've corrected the code, as noted below:
Dim context As ProductPMContext
Dim productCollectionView As DomainCollectionView
Dim products As IEnumerable(Of ProductPM)
Public Sub New()
InitializeComponent()
context = New ProductPMContext()
'You need to initialise the products collection
products = New EntityList(Of ProductPM)(context.ProductPMs)
Dim collectionViewLoader As DomainCollectionViewLoader(Of ProductPM)
'Have fixed this line, using AddressOf
collectionViewLoader = New DomainCollectionViewLoader(Of ProductPM)(AddressOf LoadProductPMList, AddressOf OnLoadProductPMListCompleted)
productCollectionView = New DomainCollectionView(collectionViewLoader, products)
productCollectionView.Refresh()
ProductListBox.ItemsSource = productCollectionView
End Sub
Public Function LoadProductPMList() As LoadOperation(Of ProductPM)
Return context.Load(context.GetProductsQuery)
End Function
Private Sub OnLoadProductPMListCompleted(ByVal op As LoadOperation(Of ProductPM))
If op.HasError = True Then
ElseIf op.IsCanceled = False Then
CType(products, EntityList(Of ProductPM)).Source = op.Entities
End If
End Sub
Hope this helps...
Chris
来源:https://stackoverflow.com/questions/9902824/silverlight-domaincollectionview-in-vb-net