Silverlight DomainCollectionView in VB.NET

拥有回忆 提交于 2019-12-24 23:56:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!