Có một chút rắc rối khi cố gắng lấy vị trí của một mục trong một ListView khi nó được khai thác.Biểu mẫu Xamarin - Nhận vị trí của mục được chọn trong Listview
Heres mã của tôi:
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
};
}
Bất kỳ trợ giúp sẽ được đánh giá rất nhiều.
SOLVED
Đã phải thay đổi ItemTapped-ItemSelected
Sau đó bên trong ItemSelected Tôi chỉ cần thêm vào dòng này:
var i = (listView.ItemsSource as List<EventItems>).IndexOf(e.SelectedItem as EventItems);
Xin lỗi vì điều này, nhưng điều gì sẽ MyObject? – ADuggan
Đừng bận tâm tin nhắn cuối cùng của tôi, tôi đã nhận được nó làm việc. – ADuggan
Cách thực hiện điều đó nếu 'ItemsSource' thuộc loại' ObservableCollection> '? –
testing