Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WP7.1 ListBox selected index does not seem to work as expected. How a selecteditem can be displayed on top?

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: http://tinyurl.com/9298cdx
  • 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:

  • To make it even easier, the code can be downloaded: https://docs.google.com/file/d/0B8xOhdKHzbkyaWFLRHN0WjRoajg/edit

Thanks very much!

like image 515
Shahaab Avatar asked Oct 12 '12 12:10

Shahaab


People also ask

How do you check ListBox is selected or not?

To determine the items that are selected, you can use the Selected property of the list box. The Selected property of a list box is an array of values where each value is either True (if the item is selected) or False (if the item is not selected).

Which of the following property returns the index of a selected item in a ListBox?

If you want to obtain the index position of the currently selected item in the ListBox, use the SelectedIndex property.

What is the usage of SelectedIndex property of ListBox?

For a standard ListBox, you can use this property to determine the index of the item that is selected in the ListBox. If the SelectionMode property of the ListBox is set to either SelectionMode.

What are the various ways of selecting items from a ListBox?

Multiselect listbox: Users can select or deselect one or more items by holding down the Shift, Command, or Control key while clicking on items. Multiselect listbox with checkboxes: This type of listbox includes checkboxes to make multiple selection more obvious.


1 Answers

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.

like image 53
Shahaab Avatar answered Nov 15 '22 00:11

Shahaab