WP7 - listbox Binding

Posted by Jeff V on Stack Overflow See other posts from Stack Overflow or by Jeff V
Published on 2011-01-02T03:32:31Z Indexed on 2011/01/02 3:54 UTC
Read the original article Hit count: 183

Filed under:

I have an ObservableCollection that I want to bind to my listbox...

lbRosterList.ItemsSource = App.ViewModel.rosterItemsCollection;

However, in that collection I have another collection within it:

 [DataMember]
    public ObservableCollection<PersonDetail> ContactInfo
    {
        get
        {
            return _ContactInfo;
        }
        set
        {
            if (value != _ContactInfo)
            {
                _ContactInfo = value;
                NotifyPropertyChanged("ContactInfo");
            }
        }
    }

PersonDetail contains 2 properties: name and e-mail

I would like the listbox to have those values for each item in rosterItemsCollection

RosterId = 0;
RosterName = "test";
ContactInfo.name = "Art";
ContactInfo.email = "[email protected]";

RosterId = 0;
RosterName = "test"
ContactInfo.name = "bob";
ContactInfo.email = "[email protected]";

RosterId = 1;
RosterName = "test1"
ContactInfo.name = "chris";
ContactInfo.email = "[email protected]";

RosterId = 1;
RosterName = "test1"
ContactInfo.name = "Sam";
ContactInfo.email = "[email protected]";

I would like that listboxes to display the ContactInfo information.

I hope this makes sense...

My XAML that I've tried with little success:

<listbox x:Name="lbRosterList" ItemsSource="rosterItemCollection">
<textblock x:name="itemText" text="{Binding Path=name}"/>

What am I doing incorrectly?

© Stack Overflow or respective owner

Related posts about windows-phone-7