none
ISupportIncrementalLoading RRS feed

  • Question

  • Hello everyone,

    I am trying to make a collection of items that support ISupportIncrementalLoading
    here's what i have done

     Public Class Context : Inherits ObservableCollection(Of Item) : Implements ComponentModel.INotifyPropertyChanged, ISupportIncrementalLoading
            Public Property ItemsCount As ULong
                Get
                    Return Me._ItemsCount
                End Get
                Set(value As ULong)
                    Me._ItemsCount = value
                    Me.OnPropertyChanged(New PropertyChangedEventArgs("ItemsCount"))
                End Set
            End Property
    
            Private Async Function LoadMoreItemsAsync(ByVal c As Threading.CancellationToken, ByVal count As UInteger) As Task(Of LoadMoreItemsResult)
                Try
                    Await LoadMoreItemsHandler.AsTask
                    Return New LoadMoreItemsResult With {
                    .Count = CUInt(Items.Count)
                }
                Catch
    
                End Try
            End Function
    
            Public LoadMoreItemsHandler As IAsyncOperation(Of Integer)
            Public Function LoadMoreItemsAsync(count As UInteger) As IAsyncOperation(Of LoadMoreItemsResult) Implements ISupportIncrementalLoading.LoadMoreItemsAsync
                Return AsyncInfo.Run(Function(c) LoadMoreItemsAsync(c, count))
            End Function
    
            Public ReadOnly Property HasMoreItems As Boolean Implements ISupportIncrementalLoading.HasMoreItems
                Get
                    Return Me.Count < Me.ItemsCount
                End Get
            End Property
        End Class

    And in the MainPage i have this function i want to bind to LoadMoreItemsHandler so when the collection wants to load more items it will invoke LoadMoreItemsHandler 

            Private Async Function LoadItemsAsync(ByVal count As Integer) As Task
                If Me.ComboBox_InventoryContexts.SelectedItem Is Nothing _
              OrElse Not Me.ComboBox_InventoryContexts.SelectedItem.GetType Is GetType(DataModels.InventoriesModel.Context) _
              OrElse Me.Account Is Nothing _
              OrElse Me.Inventory_CurrentProfile Is Nothing _
              Then Return
    
                Dim CurrentInventory = CType(Me.GridView_Inventories.SelectedItem, DataModels.InventoriesModel.Inventory)
    
                Dim StartID = If(Me.Inventory_CurrentContext.Count = 0, 0, Me.Inventory_CurrentContext.Last.AssetID)
                Dim InventoryResponse = Await Me.Account.FetchInventoryAPIAsync(Me.Inventory_CurrentProfile.SteamID,
                                                                             CurrentInventory.AppID,
                                                                             Me.Inventory_CurrentContext.ID,
                                                                             "English", count, StartID).ConfigureAwait(True)
                If Not InventoryResponse Is Nothing Then
                    Select Case InventoryResponse.Result
                        Case Kit.Steamworks.Adapters.ESteamWebResponseResult.success
                            Dim AddedItems = CurrentInventory.UpdateInfo(InventoryResponse.InventoryCallBack)
                            If Not AddedItems Is Nothing Then
                                For Each Item In AddedItems
                                    If Not Item.IconURI Is Nothing Then
                                        Item.Icon = Await App.ImageCache.GetFromCacheAsync(Item.IconURI)
                                    End If
                                Next
                            End If
                    End Select
                End If
            End Function

    I have been trying for hours and still can't do that, and i am doing this in this way because i want to have x collections and each one of them will use a different way to load items.

    Anyone can help?
    Thanks in advance.

    Sunday, April 7, 2019 5:37 AM

All replies

  • Hi,

    Well, I still can't understand what's the problem. Does it give an error? Does it work? What's the behavior you want to get and what's the behavior you are getting now?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 8, 2019 9:46 AM
    Moderator
  • Hey,

    Sorry i was busy the last month.

    What i am trying to achieve is to have a collection that load items incrementally, but my problem is that the method that load items is not within the Collection class, however it is in MainPage, and my problem is letting my collection run a method in MainPage for loading items.

    With kind regands

    I. Sabri

    Sunday, May 19, 2019 7:46 AM
  • Hey again,

    I was trying to fix it, the good news its working, and the bad news, the program hangs for a second or two when loading items.
    here is the new code:

    ItemsCollection : Inherits ObservableCollection(Of Item) : Implements ISupportIncrementalLoading

    #Region "Methods"
    
            Public IAsyncOperation As Task(Of LoadMoreItemsResult)
    
            Public Function LoadMoreItemsAsync(count As UInteger) As IAsyncOperation(Of LoadMoreItemsResult) Implements ISupportIncrementalLoading.LoadMoreItemsAsync
                Dim coreDispatcher As Windows.UI.Core.CoreDispatcher = Window.Current.Dispatcher
                Return Task.Run(Of LoadMoreItemsResult)(Async Function()
                                                            Me.IsLoading = True
                                                            Dim Result As LoadMoreItemsResult
                                                            If Not IAsyncOperation Is Nothing Then
                                                                Await coreDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, Async Sub()
                                                                                                                                               Result = Await IAsyncOperation
                                                                                                                                           End Sub)
                                                            End If
                                                            Me.IsLoading = False
                                                            Return Result
                                                        End Function).AsAsyncOperation
            End Function
    
            Public ReadOnly Property HasMoreItems As Boolean Implements ISupportIncrementalLoading.HasMoreItems
                Get
                    Return Me.Items.Count < Me.TotalItemsCount
                End Get
            End Property
    
            Public Overloads Function Contains(ByVal AssetID As ULong) As Boolean
                For Each _Item In Me
                    If _Item.AssetID = AssetID Then
                        Return True
                    End If
                Next
                Return False
            End Function
    #End Region

    MainPage

        Private Async Function LoadItemsAsync(ByVal count As Integer) As Task(Of LoadMoreItemsResult)
                Dim Account As Account
                If Me.Sender.ActiveAccount.Username = Me.ComboBox_WebFunctions_Accounts.SelectedItem Then
                    Account = Me.Sender.ActiveAccount
                Else
                    Account = Me.Sender.AccountsCollection.Item(CType(Me.ComboBox_WebFunctions_Accounts.SelectedItem, String))
                End If
                If Account Is Nothing Then Return Nothing
                If Me.ComboBox_WebFunctions_InventoryContexts.SelectedItem Is Nothing _
              OrElse Not Me.ComboBox_WebFunctions_InventoryContexts.SelectedItem.GetType Is GetType(DataModels.InventoriesModel.Context) _
              OrElse Me.WebFunctionsProfile Is Nothing _
              Then Return Nothing
    
                Dim CurrentInventory = CType(Me.GridView_WebFunctions_Inventories.SelectedItem, DataModels.InventoriesModel.Inventory)
    
                Dim StartID = If(Me.WebFunctions_Inventory_CurrentContext.Items.Count = 0, 0, Me.WebFunctions_Inventory_CurrentContext.Items.Last.AssetID)
                Dim InventoryResponse = Await Account.Community.FetchInventoryAPIAsync(Me.WebFunctionsProfile.SteamID,
                                                                             CurrentInventory.AppID,
                                                                             Me.WebFunctions_Inventory_CurrentContext.ID,
                                                                             "English", count, StartID).ConfigureAwait(True)
                If Not InventoryResponse Is Nothing Then
                    Select Case InventoryResponse.Result
                        Case Adapters.Valve.ESteamResponseResult.success
                            Dim AddedItems = CurrentInventory.UpdateInfo(InventoryResponse.InventoryCallBack)
                            If Not AddedItems Is Nothing Then
                                For Each Item In AddedItems
                                    If Not Item.IconURI Is Nothing Then
                                        Item.Icon = Await App.ImageCache.GetFromCacheAsync(Item.IconURI)
                                    End If
                                Next
                            End If
                            Me.WebFunctions_Inventory_CurrentContext.Items.IAsyncOperation = LoadItemsAsync(75)
                            Return New LoadMoreItemsResult With {.Count = AddedItems.Count}
                    End Select
                End If
                Return Nothing
            End Function

    and when i create the collection i assign IAsyncOperation

    Me.WebFunctions_Inventory_CurrentContext.Items.IAsyncOperation = LoadItemsAsync(75)

    So my question is, why does the program hangs for a second or two when loading?

    Thursday, May 23, 2019 7:23 AM