我基本上有一个列表视图,当我单击列表视图项时具有此功能。
当我运行它并单击该项目时,我会在我的应用程序崩溃之前收到以下显示警报。
DisplayAlert 1,然后是 DisplayAlert 2,然后是 DisplayAlert 1,然后我的应用程序崩溃了。使用“指定的演员表无效”。
我不知道为什么我会再次收到 DisplayAlert 1,以及为什么会崩溃。
public async void OnSelection(object sender, SelectedItemChangedEventArgs e)
{
await DisplayAlert("1", "1", "1");
if (e.SelectedItem == null)
{
return; // ItemSelected is called on deselection, which results in SelectedItem being set to null
}
//((ListView)sender).SelectedItem = null;
await DisplayAlert("2", "2", "2");
// Cast to zoneviewmodel type
var selectedZone = (ViewModel.ZoneViewModel)e.SelectedItem;
await DisplayAlert("3", "3", "3");
// Redirect to login
await Navigation.PushAsync(new LoginPage(selectedZone.Address));
await DisplayAlert("4", "4", "4");
// send message containing information to fill loginpage information
MessagingCenter.Send<MainPage, ViewModel.ZoneViewModel>(this, "loginInfo", selectedZone);
}