-1

有人知道如何在一个 ListBox 中绑定两个 ObservableCollections 吗?这两个 ObservableCollections 都有一个要显示在 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 { ... string name (get;set;} ...

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

为什么不能显示“姓名”?

4

1 回答 1

0

复合系列就是您要寻找的。例子

于 2012-09-22T10:45:33.313 回答