0

I am a novice in Xamarin and C#. I am trying to get the key and the value of an Item that I select in a listview.

Here is my code to get my listview, this work fine cause I get a list of items:

//search on the list view
private async Task SearchMyFriendAsync(object sender, TextChangedEventArgs e)
{
    string keyword = SearchFriend.Text;
    Dictionary<string, string> words = await usermanager.GetUserList(keyword);
    FriendsListView.ItemsSource =  words;
}

When I select an item, I get an error; here is the code :

public async void OnSelectedFriendDescript(object obj, ItemTappedEventArgs args)
{
    var FriendName =  (KeyValuePair<string, string>)args.Item;
}

And here is the error :

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object.

Here is a screenshot:

enter image description here

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388

0 Answers0