任何人都可以在VB.NET中共享DomainCollectionView的代码吗? 我有一个错误,没有为'Private Sub OnLoadProductPMListCompleted(op As System.ServiceModel.DomainServices.Client.LoadOperation(Of ProductPM))'的参数'op'指定参数。
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
答案 0 :(得分:1)
对不起,迟到的回复,我一直很忙。我已经更正了代码,如下所示:
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
希望这会有所帮助......
克里斯