xamarin/Xamarin.Forms
[Bug][UWP] SelectedItem of ListView on UWP always returns null when populated with webapi data
Aberta
#7.954 aberto em 11 de out. de 2019
a/listviewe/4 :clock4:help wantedinactivep/UWPt/bug :bug:up-for-grabs
Métricas do repositório
- Stars
- (5.644 estrelas)
- Métricas de merge de PR
- (Nenhuma PRs mesclada em 30d)
Description
Description
This issue only happens on UWP. No problem on Android and I have not tested it on iOS yet.
ListViewonMainPageis populated with web api data.- When we click any item, we should be navigated to its edit page. However because
SelectedItemalways returnsnull(only on UWP) then we never reach the edit page. - No problem if I populate the list view with hard-coded data.
The following code snippet is the focal point of the issue.
protected override async void OnAppearing()
{
base.OnAppearing();
// If I populate listview with data from web api
// then e.SelectedItem becomes always null.
// This only happens on UWP.
// It works just fine on Android. I haven't tested on iOS.
listViewTodo.ItemsSource = await ts.GetTodoItemsAsync();
// But if I populate listview with hard-coded data,
// there is no problem on UWP (and Android).
//listViewTodo.ItemsSource = new TodoItem[]
//{
// new TodoItem { Text = "Accompanying ...", Complete = true },
// new TodoItem { Text = "Bathing ...", Complete = false }
//};
}
private async void ListViewTodo_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
// ti becomes always null on UWP if listview is populated with web api data
TodoItem ti = e.SelectedItem as TodoItem;
if (ti != null)
await Navigation.PushAsync(new UpdatePage(ti));
}
Steps to Reproduce
See my repo: https://github.com/samrgc/Bug_UWP_Original. There are two solutions:
- One for backend web api
- One for Xamarin.Form clients
Note: Don't forget to adjust
public TodoService()
{
msc = new MobileServiceClient("http://192.168.1.2:45455");
mst = msc.GetTable<TodoItem>();
}