WP7 -

2011-01-02 15 views
1

は私が私のリストボックスにバインドするのObservableCollectionを持っているバインディングリストボックス...WP7 -

lbRosterList.ItemsSource = App.ViewModel.rosterItemsCollection; 

しかし、そのコレクションに私は、その中に別のコレクションを持っている:

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

PersonDetailが含まれています2プロパティ:名前と電子メール

私はリストボックスにそれらの値を持たせたい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]"; 

私はそのリストボックスにContactInfo情報を表示したいと思います。

私は、これは理にかなって願ってい

...私はほとんど成功して試してみた

私のXAML:

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

私が間違って何をしているのですか?

答えて

4
はこれにあなたのバインディングパスを変更

<ListBox x:Name="lbRosterList" DataContext="{Binding}" ItemsSource="{Binding rosterItemCollection}"> 
<TextBlock x:Name="itemText" Text="{Binding Path=ContactInfo.name}"/> 

次に、あなたのコード内で(ページのコンストラクタでInitializeComponents後)は、この操作を行います。

lbRosterList.DataContext = App.ViewModel; 

このfree bookでこの種のもののための優秀なリファレンスCharles Petzold:第12章、363ページ

リストボックスからDataContext属性を削除し、0を設定することもできますページ自体の新しいデータバインドされたアプリケーションを作成すると、そのデフォルトの例が意味することがわかります。

+0

私はその本をダウンロードし、特にそのページを見ました。私はあなたの提案を試みましたが、いくつかのバインドが起こっているように見えますが、 "名前"プロパティのテキストは表示されません... – webdad3

+0

更新された回答を参照してください – theChrisKent

+0

この作品はあなたのために働いたのですか、 – theChrisKent