热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何通过按钮聚焦ListView的TextCell?-HowtofocusListView'sTextCellbybutton?

IneedtofocusTextCellsonebyoneviaabuttonclick.ItriedlistView.ScrollTo.我需要通过点击按钮逐个关注Tex



I need to focus TextCells one by one via a button click. I tried listView.ScrollTo.


我需要通过点击按钮逐个关注TextCells。我试过listView.ScrollTo。


private void Button_Clicked_1(object sender, EventArgs e)
{
listViewJson.ItemTapped += ListViewJson_ItemTapped;
}

private void ListViewJson_ItemTapped(object sender, ItemTappedEventArgs e)
{
var focusing = e.Item;
listViewJson.ScrollTo(focusing, ScrollToPosition.MakeVisible, true);
}



1 个解决方案





#1





0  


Firstly, try to define an index to detect which cell to be selected. Then change the index via button click like:


首先,尝试定义索引以检测要选择的单元格。然后通过按钮点击更改索引,如:


int selectedIndex = 0;
private void MyBtn_Clicked(object sender, EventArgs e)
{
if (selectedIndex == dataList.Count) selectedIndex = 0;
myListView.SelectedItem = dataList[selectedIndex++];
}

when the TextCell is selected the ListView's ItemSelected event will fire, you can put your code in it like:


当选择TextCell时,ListView的ItemSelected事件将触发,您可以将代码放入其中:


private void MyListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
//try to do something
}

Here is my code behind for you referring to:


这是我的代码,你指的是:


ObservableCollection dataList = new ObservableCollection();

int selectedIndex = 0;

public MainPage()
{
InitializeComponent();

for (int i=0; i<10; i++)
{
dataList.Add("item" + i);
}

myListView.ItemsSource = dataList;

myListView.ItemSelected += MyListView_ItemSelected;

MyBtn.Clicked += MyBtn_Clicked;
}

private void MyListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
//try to do something
}

private void MyBtn_Clicked(object sender, EventArgs e)
{
if (selectedIndex == dataList.Count) selectedIndex = 0;
myListView.SelectedItem = dataList[selectedIndex++];
}






推荐阅读
author-avatar
手机用户2502900175
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有