有人知道如何在一个ListBox中绑定两个ObservableCollections吗? 这两个ObservableCollections都有一个属性字符串“name”显示在ListBox中,
在ListBox顶部区域,将显示ObservableCollection1项目,并在ListBox底部区域中我想显示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>
数据如下: class ElementFile { ... 字符串名称(get; set;} ...
}
class ElementDirectory
{
...
string name (get;set;}
...
public ObservableCollection<ElementDirectory> directorys { get; set; }
public ObservableCollection<ElementFile> files { get; set; }
...
}
为什么无法显示“名称”?