This is a migrated thread and some comments may be shown as answers.

Manual blocking VirtualDataCollection.ItemsLoading event

2 Answers 70 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vitalii
Top achievements
Rank 2
Vitalii asked on 21 Aug 2013, 10:24 AM
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 Answers, 1 is accepted

Sort by
0
Vitalii
Top achievements
Rank 2
answered on 21 Aug 2013, 10:39 AM
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.
0
Deyan
Telerik team
answered on 21 Aug 2013, 02:31 PM
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 >>
Tags
DataBoundListBox
Asked by
Vitalii
Top achievements
Rank 2
Answers by
Vitalii
Top achievements
Rank 2
Deyan
Telerik team
Share this question
or