private void clickAdd(object sender, RoutedEventArgs e) { var item = ((Button)sender).DataContext; var itemIndex = userList.Items.IndexOf(item); string candidate = users[itemIndex]; bool result = controller.addNewFriend(username, candidate); string msg = "Adding " + candidate + " to friends list"; if (!result) { Utils.Instance.errorAndExit("Error trying to access users records"); } bindNonUserList(); MessageBox.Show(msg + " succeed"); }