1

I have what I thought was an ideal scenario for a CompositeCollection, except it seems that changes to the items of the underlying collection do not appear in the CompositeCollection (or, at any rate, not in the control whose source is this CompositeCollection).

EDIT 1: both underlying collections are ObservableCollections.
EDIT 2: the new/updated item gets added, but the contents of that item are not reflected in the drop-down area of the combobox. Each item implements INotifyPropertyChanged.

Am I doing something wrong or is this not supported?

Here's what I have:

<ComboBox SelectedItem="{Binding Products}">
   <ComboBox.Resources>
      <CollectionViewSource x:Key="CustomProductsSource" Source="{Binding CustomProducts}" />
   </ComboBox.Resources>
   <ComboBox.ItemsSource>
      <CompositeCollection>
          <CollectionContainer Collection="{Binding Source={x:Static local:Products.Standard}}" />
          <Separator/>
          <CollectionContainer Collection="{Binding Source={StaticResource CustomProductsSource}}"/>
      </CompositeCollection>                                        
    </ComboBox.ItemsSource>                                     
</ComboBox>
4

2 回答 2

0

我修复了它 - 问题是(因为它通常是)一个白痴程序员(那就是我)。

碰巧集合的 Item(单个 Product 类)有一个覆盖的ToString()方法返回 Product 实例的 Name 属性。因此,组合框显示了它应该显示的内容,即产品的名称,除了它是根据ToString()方法进行的......因为我忘记为 ComboBox 创建一个数据模板。难怪没有反映对名称的更改

于 2013-07-16T20:32:41.687 回答
0

Products.Standard和是什么类型的集合CustomProducts?如果他们没有更改通知(不实施INotifyCollectionChanged),那么CompositeCollection就无法知道发生了什么变化。

例如ObservableCollection<>在这种情况下应该可以正常工作。

于 2013-07-10T15:57:36.660 回答