Manual blocking VirtualDataCollection.ItemsLoading event

3 posts, 0 answers
  1. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 21 Aug 2013 Link to this post

    As mentioned here, i faced some problems with this event.
    So, i decided to try workaround. 

    As i don't have SelectedIndex during page loading, i decided to use it for blocking requests. Bu default, it should be String.Empty, but once it is set, requests can to proceed.
    public void OnNavigatedFrom()
            {
                SelectedIndex = String.Empty; // Empty, when navigating from
                VirtualDataCollection.Clear();
     
                Cleanup();
            }
    public async void OnNavigatedTo()
            {
                var answer = await _dataService.ReadFromCacheAsync(SelectedIndex); // Now, SelectedIndex holds correct id
                if (answer.Status == AnswerDataServiceStatus.Ok)
                {
                    lock (locker)
                    {
                        var currentIndex = SelectedIndex; // storing
                        SelectedIndex = String.Empty; // emptying
     
                        VirtualDataCollection.Count = answer.TotalItems;
                        VirtualDataCollection.LoadItems(0, answer.Collection);
     
                        SelectedIndex = currentIndex; // restoring
                    }
                }
            }
    Event itself: 
    private async void VirtualDataCollectionOnItemsLoading(object sender, VirtualizingDataCollectionItemsLoadingEventArgs e)
            {
                if (String.IsNullOrEmpty(SelectedIndex)) return; // Leaving, if id is empty
     
                var answer = await _dataService.RequestServerAsync(SelectedIndex, e.StartIndex, e.Count);
                if (answer.Status == AnswerDataServiceStatus.Ok) // && answer.Collection.SequenceEqual(VirtualDataCollection.))
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        lock (locker)
                        {
                            var currentIndex = SelectedIndex; // No double rising at LoadItems or Count
                            SelectedIndex = String.Empty;
     
                            VirtualDataCollection.Count = answer.TotalItems;
                            VirtualDataCollection.LoadItems(e.StartIndex, answer.Collection);
     
                            SelectedIndex = currentIndex;
                        }
                    });
                }
            }

    Page constructor
    VirtualDataCollection = new VirtualizingDataCollection(1, Constants.PAGE_SIZE);
                VirtualDataCollection.ItemsLoading += VirtualDataCollectionOnItemsLoading;

    However, now, sometimes, ItemsLoading is not rising at all, when user scrolls down fast enough.. any suggestions? Maybe locker is not enough?
  2. Vitalii
    Vitalii avatar
    104 posts
    Member since:
    Jul 2013

    Posted 21 Aug 2013 Link to this post

    Yep, the locker is the reason. It cannot be used, because VirtualDataCollection.LoadItems() is quite long, and user can scroll down fast enough. I should consider another solution.

    However, it is a bit strange: i cancelled loading of page 2 (by just returning), and page 3 is never even tries to be loaded. I guess, you can make paging requests independent of previous result.
  3. DevCraft banner
  4. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 21 Aug 2013 Link to this post

    Hi Vitalii,

    Thanks for writing.

    We would like to kindly request you to use a single thread regarding the VirtualizingDataCollection difficulties you are facing. This will make it easier for us to handle the case and quickly assist you.

    For the purpose of faster support, please send us a ZIP containing a sample project that we can use to reproduce the issues you are facing and directly debug them. In this way we will be able to quickly identify the possible ways of overcoming them.

    Thanks for your understanding and for the time taken.

    Regards,
    Deyan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINDOWS PHONE 7.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top