Did you ever try to use the ListView for Windows 8 Applications? If you had a more complicated scenario where you need to ensure that the selected item from your code is visible maybe you had the following problem…
How can I make the selected item visible? If I have a lot of items in my scroll list than the selected item will not be visible when we select it.
listView.set(i).done();
In this way we select the ‘i’ element of the list. Also the set() method unselect the rest of the items that were selected already. To be able to show it in the visible part of the list we need to call the ensureVisible() method after we set it.
listView.set(i).done();
listView.ensureVisible(i);
But in more complicated cased you will notify that this will not work. Even if the ensureVisible() method is called nothing will happen. Usually this case appears when the method is called in a “callback” or in a complete, error or progress of a promise.
Even if you try o the ensureVisible in a msSetImmediate it will not work:
listView.set(i).done();
msSetImmediate(function(){ listView.ensureVisible(i); });
A fix for this problem is using the indexOfFirstVisible. This property of the list view gives us the possibility to set the index of the first visible element. The working code would look like this:
listView.set(i).done();
msSetImmediate(function(){ listView.indexOfFirtsElement = i; });
I hope that I could help you.
I tried this and indexOfFirstElement is undefiend
ReplyDeleteYou can find references about this method here: http://msdn.microsoft.com/en-us/library/windows/apps/hh700691.aspx
Delete