how to set a focus of Listview item in Metro apps?

北城以北 提交于 2019-12-08 09:56:56

问题


I have a listview in my metro-app.I want to set a focus of last-item in my listview?How can I set a focus of a listview-item?Can anyone help me?

Thank you.


回答1:


You need to use the ListViews currentItem property: http://msdn.microsoft.com/en-us/library/windows/apps/hh700672.aspx

Specifically, assign it an object with the index of the data item you want selected (from your data source), and the hasFocus and showFocus properties set:

var yourListView = getYourListViewFromSomewhere();
yourListView.currentItem = { index: 8, hasFocus: true, showFocus: true }



回答2:


Are you asking to set the focus or actually select it? If you want to do the latter, all you have to do is the following:

var indexToSelect = listView.itemDataSource.length - 1;
listView.selection.set(indexToSelect);

That will get the index of the last item in the list, and then select the item.

Otherwise Dominic's solution should work for just setting the focus.




回答3:


Here's a piece of code to change the selected index of the list view to the last index

1 ) lstItems.SelectedIndex = lstItems.Items.Count - 1;

this code helps you to select the last index of the list.

2 ) lstItems.ScrollIntoView(lstItems.Items[lstItems.Items.Count - 1]);

this code helps you to scroll the list to the last index. both the lines of code are for metro app

to elaborate the second piece of code :

the lstItems.ScrollIntoView method scrolls the list to the specified list item which we obtain by lstItems.Items[lstItems.Items.Count - 1] which scrolls it to the last item of the list.



来源:https://stackoverflow.com/questions/13684678/how-to-set-a-focus-of-listview-item-in-metro-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!