【发布时间】:2019-08-22 17:28:24
【问题描述】:
如果我们尝试将组合框保留在 ItemsCotrol 中,则不会显示组合框项目。 Please click here for understanding my requirement
我的要求是在 ItemsControl 中保留一个组合框,以便 ItemsControl 中包含 5 个组合框,并且每个组合框都将包含我们可以选择的项目集合。因此,为此我尝试使用以下代码并能够在 ItemsControl 中获取组合框,但组合框集合已被填充,请提供任何建议或解决方法..
<xamDataPresenter:Field Label="Reqs" BindingType="Unbound" Row="0" Column="4">
<xamDataPresenter:Field.CellValuePresenterStyle>
<Style TargetType="{x:Type xamDataPresenter:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type xamDataPresenter:CellValuePresenter}">
<ItemsControl Name="I" ItemsSource="{Binding Path=DataItem.CollectionCount}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=DataItem.Collection}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</xamDataPresenter:Field.CellValuePresenterStyle>
</xamDataPresenter:Field>
【问题讨论】:
-
您在组合框中缺少 ItemsSource?
-
您的组合框代码没有多大意义。为什么要创建一个 TextBlock 作为 ComboBoxItem,而不是向 Combobox 提供一组项目(类似于您对 ItemsControl 所做的)。由于目前,您唯一的项目实际上是一个 TextBlock 元素本身(该项目不是 Polarity 属性提供的对象!),您需要为 ComboBox.SelectedItem 提供该 TextBlock 元素以选择它;如果您考虑一下,这当然也是相当不切实际的..
-
呃....这应该做什么:
<ComboBox SelectedItem="{Binding Item, Mode=TwoWay}"/>?对您的代码进行此编辑并没有什么意义...... -
您是在说“每个组合框都有一个我们可以选择的项目集合”。所以,开始问自己:每个 ComboBox 的那些项目集合在哪里,因此,到达这些集合的绑定是什么样的?
-
您链接的屏幕截图只显示了一些空的组合框。如果我所看到的只是一张空组合框的图片,而对它们的预期内容和目的没有任何解释,我怎么知道组合框的内容和目的应该是什么。请参阅我的第二条评论,其中我回复您说“每个组合框都将包含一组我们可以选择的项目”。
标签: wpf data-binding