2012-09-22 49 views
-1

有誰知道如何在一個ListBox中綁定兩個ObservableCollections? 這兩個ObservableCollections都有一個屬性字符串「名稱」,在列表框中顯示, enter image description here如何將兩個ObservableCollection(s)綁定到一個ListBox?

INT列表框頂部區域,將顯示ObservableCollection1項目,在列表框底部區域我想顯示ObservableCollection2項目,如何去做?

<ListBox x:Name="m_CtrlMediaList" Grid.Column="2" AllowDrop="True" SelectionMode="Extended"> 
    <ListBox.ItemsSource> 
     <CompositeCollection> 
      <CollectionContainer Collection="{Binding directorys}"/> 
      <CollectionContainer Collection="{Binding files}"/> 
     </CompositeCollection> 
    </ListBox.ItemsSource> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Vertical"> 
       <TextBlock Text="{Binding name, Mode=OneWay}" FontWeight="Bold" FontSize="14"/> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

的數據是這樣的: 類ElementFile { ... 字符串名稱(獲取;集;} ...

} 
class ElementDirectory 
{ 
... 
     string name (get;set;} 
... 
    public ObservableCollection<ElementDirectory> directorys { get; set; } 
    public ObservableCollection<ElementFile> files { get; set; } 
... 
} 

爲什麼不能顯示 「名稱」?

回答

0

composite collection就是你要找的東西Example

+3

雖然這可能在理論上回答這個問題,[這將是更可取的](http://meta.stackexchange.com/q/8259)在這裏包括答案的基本部分,並提供參考鏈接。 –

相關問題