1

I'm using this tutorial as a base for my first app. I'm trying to select a listbox item and view data from said item, but(my Android and iOS brain is having issues with this), how do I view the data binding behind that?

lstContact.ItemsSource = from contact in xmlContact.Descendants("contact")
                                 select new ContactItem
                                 {
                                     ImageSource = contact.Element("Image").Value,
                                     FName = contact.Element("FName").Value,
                                     LName = contact.Element("LName").Value
                                     Extension = contact.Element("Extension").Value,
                                     Email = contact.Element("Email").Value,
                                     ID = contact.Element("ID").Value
                                 };

This is how I'm setting it up my data source, and it's pulling correctly. How would I go about going in and getting the email or extension from said listbox item?

3
  • lstContact.ItemsSource is effectively now a IEnumerable<ContactItem>. Assuming you want a 'selected' item, are you listening to SelectionChanged? Commented May 23, 2012 at 18:19
  • if (lstContact.SelectedIndex == -1) return; var contactItem = (ContactItem)lstContact.SelectedItem; /*do something */ lstContact.SelectedIndex = -1; Commented May 23, 2012 at 18:21
  • 1
    That worked perfectly! Mind sticking that in an answer so I can accept it as the answer? Commented May 23, 2012 at 18:26

1 Answer 1

2

In your example, lstContact.ItemsSource is effectively now a IEnumerable<ContactItem>. Assuming you want a 'selected' item, in your SelectionChanged event:

public void ListBoxContainerSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstContact.SelectedIndex == -1) return; 
            ContactItem contactItem = (ContactItem)lstContact.SelectedItem; 
            /*do something */ 
            lstContact.SelectedIndex = -1;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.