【问题标题】:Combobox CompositeCollection组合框 CompositeCollection
【发布时间】:2012-03-21 04:18:23
【问题描述】:

我想要两个带有空元素集合的组合框。

我使用两个组合框:

<ComboBox x:Name="itemEditPageComboBox"
  ...
  ItemsSource="{StaticResource ItemsColl}"
 ....
/>
Collections:
<CompositeCollection x:Key="ItemsColl">
  <ComboBoxItem Content="" />
 <CollectionContainer Collection="{Binding Source={StaticResource ElementsCollection}}" />
</CompositeCollection>

<CollectionViewSource x:Key="ElementsCollection" Source="{Binding Path=...}" /> 

行为

依次选择两个组合框,之后 - 其中一个被删除空元素。

错误:

System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type; Type='ComboBoxItem'

请告诉我该怎么做?

最好的问候!

【问题讨论】:

    标签: wpf xaml data-binding combobox


    【解决方案1】:

    您不能在两个ComboBoxes 中使用相同的ComboBoxItem,错误也应该很清楚:如果将ComboBoxItem 添加到定义了ItemTemplateComboBox,则不会应用于ComboBoxItem,因为它已经具有创建容器的类型。此错误可能是问题,也可能不是问题,具体取决于您想要什么。

    如果你想为两个ComboBoxes 使用集合,你应该添加一个string,或者如果你想要更复杂的一个类的实例(它可能应该有一个隐含的DataTemplate 与之关联)。不要直接添加ComboBoxItem

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多