8

SCENARIO:

  • In windows Phone 7, I am using a list box.
  • Assume there are 200 items.
  • Now I select 150th item of the list
  • I want the list to load and select (and show) the 150th item on the top of the list after loading.

PROBLEM:

  • I am using the HookScrollViewer() as mentioned on this page(ListBox offset in WP7)
  • The first time the item is loaded the list doesn't show the right item (say it shows 148th item).
  • I get out of that page and click the item 150th again
  • Now the list index is correct and it shows 150th item exactly on the top.

QUESTION:

  • Am I using right solution?
  • What is wrong I am doing, I have tried to identify the solution but failed!

HINT:

  • If you have a windows phone, please download the app
  • Open any chapter and bookmark something (by Long-pressing) in the middle of the chapter.
  • Close the application, and open the application again.
  • Click on the bookmark to open it.
  • The first time it won't go to the exact location.
  • Now DON'T close the app, just press back button and click the bookmark again.
  • This time the location is correct!
  • The question is, what's wrong with the first time?

THE CODE OF THE READING PAGE:

Thanks very much!

8
  • I checked the XAML, and nothing's wrong there. I removed the animation, it didn't work either.
    – Shahaab
    Oct 12, 2012 at 16:44
  • I added UpdateLayout() for both ScrollViewer and ListBox, it didn't help.
    – Shahaab
    Oct 12, 2012 at 16:45
  • The point is that it is working fine, the second time it works as it should, why is it not working the first time? Is there anything which I am missing?
    – Shahaab
    Oct 12, 2012 at 16:46
  • iv'e never created a Windows phone application , can you use Behaviors ? i would create a behavior and use the functionality described in HookScrollViewer() in the Behavior's OnAttatch() and Invoke() so that even when the page loads it would be invoked , does that sound like a good solution , if so i'll write a quick Behavior for a Selector ...
    – eran otzap
    Oct 12, 2012 at 18:37
  • Thanks eran, I am also a beginner, this is my very first mobile app of any kind, and when I started this, I knew nothing about c#. Therefore, I don't know if behaviours will solve the problem. I would like to try however. please write that down and I'll try. Thanks!
    – Shahaab
    Oct 12, 2012 at 19:14

2 Answers 2

1

After struggling, I have found the actual problem and its solution.

Actual Problem:

  • I am using external fonts, other than those which are included in the WP by default.
  • The external fonts need some time to get loaded into the memory and then the text is displayed.
  • In the mean time the list is loaded already, while the font is being loaded.
  • Finally the text is displayed, and (could be because of expansion), the selected index location is moved down.
  • Without closing the app, the font seems to stay in the memory, and the next time it doesn't take long time, and the pointer id displayed correctly.

My Solution:

  • I loaded the (external) fonts while the main page is being loaded. It takes negligible amount of time and hence, doesn't affect the efficiency of the app (in terms of loading time)

I wish if any architect can explain in better way that what has been happening, or in other words, I am interested to know the technical background of the "actual problem".

Thanks very much to all those who gave suggestions.

0

I guess your data not update .You can try to Use INotifyPropertyChanged ,Look at the example you will understand how to use

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.