我在点击时尝试获取ListView中项目的位置时遇到了一些麻烦.
继承我的代码:
public MainPage() { InitializeComponent(); Results(); } async void Results() { var service = new RestService(); response = await service.GetEventItemsAsync(); Debug.WriteLine("Found: " + response.Count + " events"); listView.ItemsSource = response; listView.ItemTapped += async (sender,e) => { // Get position of item tapped }; }
任何帮助将不胜感激.
解决了
不得不将ItemTapped更改为ItemSelected
然后在ItemSelected里面我刚才添加了这一行:
var i = (listView.ItemsSource as List<EventItems>).IndexOf(e.SelectedItem as EventItems);
解决方法
在SelectedItem事件中尝试这样:
var index = (myListView.ItemsSource as List<MyObject>).IndexOf (e.SelectedItem as MyObject);