EnableAsyncBalance and BeginAsyncBalance method

4 posts, 1 answers
  1. keith patton
    keith patton avatar
    7 posts
    Member since:
    Sep 2009

    Posted 28 May 2011 Link to this post

    I am using the MVVM pattern and found this blog post:
    http://blogs.telerik.com/blogs/posts/11-05-12/windows_phone_7_mvvm_1_raddataboundlistbox.aspx

    However, when I look at your examples there is in the ListExampleBase.cs a method call BeginAsyncBalance in addition to the ItemsSource property being set manually in code (as opposed to a Binding element in xaml in the View which is what I currently have as per the blog post.

      protected virtual void DisplayData(IEnumerable items)
            {
    ........

                this.Dispatcher.BeginInvoke(() =>
                {
                    this.ListBox.BeginAsyncBalance();
                    this.ListBox.ItemsSource = items;
                });
            }


    In addition, when the list box has been loaded (in the OnLoaded method of same class), the following property is set. Again, is this important, and what exactly does this do?

              this.ListBox.IsAsyncBalanceEnabled = this.EnableAsyncBalance;

    If you could please explain whether it is best practice to set this property and call this method at these particular points in the control's lifecycle? If so, why do they need to be controlled manually?

    I'm really after a 'sensible default' here. My listbox will have 'More' enabled to allow paging, but is unlikely to get bigger than 1-200 items. The templating will however be very rich if this helps. 
  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 31 May 2011 Link to this post

    Hi Keith,

    Thanks for writing and for your questions.

    You can find more information about the asynchronous balance feature here:

    http://www.telerik.com/help/windows-phone/raddataboundlistbox-features-asynchronous-balance.html

    In general, this feature instructs the control to offload the UI thread upon the realization of a single RadDataBoundListBoxItem (the visual container for a single data item) thus leaving space for rendering and manipulation events processing. Since sometimes the user may define more complex Item Templates thus making the initial loading time consuming, the async balance allows for improving the user experience by not loading all containers at once but at very small time intervals thus leaving the UI thread to process rendering and user input as well.

    I hope this answers your questions.

    Do not hesitate to get back to us in case you have further questions or need assistance.

    Best wishes,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. keith patton
    keith patton avatar
    7 posts
    Member since:
    Sep 2009

    Posted 02 Jun 2011 Link to this post

    Thanks. So how can we apply an MVVM binding from a view model property? Do we have to manually apply these properties in code and set ItemsSoruce to get the desired effect, or can i get the benefits of this approach on my listbox declaratively in xaml, i couldn't see how?

    I'm trying to reduce or eliminate any extra code if i wanted this behaviour as the default.
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 02 Jun 2011 Link to this post

    Hi Keith,

    You can completely configure the RadDataBoundListBox in XAML and still use the Async Balance functionality. The ScheduleAsyncBalance method allows you to simply explicitly say that you want the next UI virtualization algorithm pass to be async. In general, you only need to have the IsAsyncBalanceEnabled set to true and the control will internally call ScheduleAsyncBalance when needed so you do not have to bother about it.

    I am attaching a demo project which demonstrates how you can use MVVM and RadDataBoundLIstBox without coding.

    I hope it helps.

    You can write back anytime you need further assistance.

    All the best,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top