VieportItems Binding

5 posts, 0 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 03 Feb 2012 Link to this post

    Hi,

    I am trying to mimic the listbox in "agenda" in WP7 Calendar. If you scroll through the listbox, the date keeps changing on the top.
    So, is there a way to identify what item the user is looking in the listbox?

    I've been thinking about the ViewPortItems - and tried to use a simple bind.
    As expected this didn't work :)

    Any Idea how to solve this with DataBoundListbox?

    Thanks in advance
    Manfred
  2. Cristovao
    Cristovao avatar
    24 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2012 Link to this post

    Hi .. I've kinda sorted it with , although I'm not certain if it's the best way...

      private void MainListBox_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
            {
                var ad = (Models.Ad)MainListBox.TopVisibleItem;
     
                int x = VM.Results.IndexOf(ad) + 1;
     
                SetHeader(x);
            }


      private void SetHeader(int index)
            {
                VM.VisibleMessage = VM.PageTitle = string.Format("{0}-{1} de {2} para {3}"
                                , index
                                , MainListBox.ViewportItems.Count() - 1 + index
                                , string.Format("{0:0,0}", VM.TotalRecords)
     
                                , AppInit.DeviceLocation.Name
                                );
            }

  3. DevCraft banner
  4. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 06 Feb 2012 Link to this post

    Hello Manfred,

    We have an excellent example of this scenario in our Agenda Viewer application which should be available for download from your account (full source code available).

    In general, the approach is to use a timer that ticks in a time interval of, let's say, 500 milliseconds and checks the top visible item in the viewport. When a particular item is positioned there, you perform the needed operation of updating a header etc. in your application.

    I hope this helps.

    Regards,
    Deyan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 06 Feb 2012 Link to this post

    Thank you for the answers.
    ManipulationCompelted does only part of the work - it updates AFTER scrolling completed - what I need is "while scrolling" - just like the Calendar App in WP7.

    The timer works - but I don't really like it.

    The sample pointed me to the TopVisibleItem property - but this seems not to work with binding.
    It looks as if INotifyPropertyChanged is not fired for this property :(

    Is this "by design" (I guess not since it is a public property on an object implementing INotifyPropertyChanged)?

    Regards
    Manfred
  6. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 07 Feb 2012 Link to this post

    Hello Manfred,

    Thanks for writing back.

    The TopVisibleItem property uses an algorithm to find the topmost item visible in the viewport. This property uses the on-demand approach to find this item and firing the PropertyChanged event for it would mean running this algorithm on each pass of the UI Virtualization routine which we certainly do not want.

    Let me also clarify some other important points related to scrolling on Windows Phone 7.5 Mango:

    We use the native ScrollViewer to utilize the off-thread manipulation that was introduced with Windows Phone 7.5 Mango to boost up UI virtualization performance. This off-thread manipulation implies that scrolling properties are not constantly implemented during scrolling, but only when the scroll amount exceeds 1/4 of the ScrollViewer's height. Therefore we do not always have the exact information where the scrollviewer's scrollbars are positioned and thus we cannot always say which item is at the top unless the scrollviewer has stopped scrolling (this is the moment when all events and properties are updated except the case with exceeding 1/4 of the ScrollViewer's height).

    Having in mind these facts, the only reasonable approach to implement the scenario you mentioned earlier is using the approach that we utilize in our AgendaViewer which we do not consider bad (using Timers is completely legal :-)).

    I hope this helps.

    All the best,
    Deyan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft banner