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

VieportItems Binding

4 Answers 50 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.
ManniAT
Top achievements
Rank 2
ManniAT asked on 03 Feb 2012, 10:11 AM
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

4 Answers, 1 is accepted

Sort by
0
Cristovao
Top achievements
Rank 1
answered on 04 Feb 2012, 12:02 PM
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
                            );
        }

0
Deyan
Telerik team
answered on 06 Feb 2012, 09:58 AM
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 >>
0
ManniAT
Top achievements
Rank 2
answered on 06 Feb 2012, 08:51 PM
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
0
Deyan
Telerik team
answered on 07 Feb 2012, 09:44 AM
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 >>
Tags
DataBoundListBox
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Cristovao
Top achievements
Rank 1
Deyan
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or