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

Jerky scrollbar and async usage

3 Answers 59 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 15 Aug 2013, 08:30 PM
1. I had found several threads about that, but either description was not complete, or answer was a bit blurry. Anyway, i'm also facing this problem. While having a list of several dozen items, it scrolls perfectly, but scrollbar is moving jerky indeed.

Sample (not mine, just was testing it, and found problem there), where you can see jerking of scrollbar (i got it on Lumia 920 device):
https://skydrive.live.com/redir.aspx?cid=0c89662af4d9c150&resid=C89662AF4D9C150!335&parid=C89662AF4D9C150!334


2. I hate those bloody callbacks, so i switched to Bcl library. Now, i'm trying to fill Listbox with own data, but somehow, page is always waiting for async call to be finished.

So, xaml: 

<telerikPrimitives:RadDataBoundListBox
                Grid.Row="1"
                EmptyContent=""
                DataVirtualizationMode="Automatic"
                CacheMode="BitmapCache"
                ItemTemplate="{StaticResource ProductsListViewerItemTemplate}"
                ItemsSource="{Binding VirtualDataCollection}"
                >

ViewModel:

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

async private void VirtualDataCollectionOnItemsLoading(object sender, VirtualizingDataCollectionItemsLoadingEventArgs e)
        {
            var answer = await _dataService.RequestServerAsync(SelectedIndex, e.StartIndex, e.Count);
            if (answer.Status == AnswerDataServiceStatus.Ok) // Added breakpoint here, page is freezing and waiting for this line
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() => 
                    VirtualDataCollection.LoadItems(e.StartIndex, answer.Collection));
            }
        }


DataService:

public async Task<ProductAnswer> RequestServerAsync(string categoryId, int startIndex, int pagesize)
        {
            Thread.Sleep(5000);

            return new ProductAnswer
                {
                    Status = AnswerDataServiceStatus.Ok,
                    Collection =
                        new List<ProductItem> {new ProductItem {name = "One"}, new ProductItem {name = "Two"}}
                };

        }

3 Answers, 1 is accepted

Sort by
0
Vitalii
Top achievements
Rank 2
answered on 16 Aug 2013, 08:09 AM
Actually, i solved second problem by moving async to background thread, but i'm not sure, if its a good idea and supported by design.

private void VirtualDataCollectionOnItemsLoading(object sender, VirtualizingDataCollectionItemsLoadingEventArgs e)
        {
            ThreadPool.QueueUserWorkItem(async o =>
                {
                    var answer = await _dataService.RequestServerAsync(SelectedIndex, e.StartIndex, e.Count);
                    if (answer.Status == AnswerDataServiceStatus.Ok)
                    {
                        DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                                              VirtualDataCollection.LoadItems(e.StartIndex,
                                                                                              answer.Collection));
                    }
                });
        }
0
Accepted
Deyan
Telerik team
answered on 19 Aug 2013, 03:41 PM
Hello Vitalii,

Thanks for writing.

1. This behavior is resulting from our current implementation of a UI virtualization mechanism. We have plans to optimize this behavior in the near future.

2. It might be so that the async in the data service provider you are using is not implemented by using background workers and thus the call is happening on the UI thread which leads to page freeze. Moving it to a background worker on your side is a good solution.

Let us know if you have additional questions.

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 >>
0
Vitalii
Top achievements
Rank 2
answered on 19 Aug 2013, 04:31 PM
Thanks, good to hear.
Tags
DataBoundListBox
Asked by
Vitalii
Top achievements
Rank 2
Answers by
Vitalii
Top achievements
Rank 2
Deyan
Telerik team
Share this question
or