【问题标题】:Bind a collection inside a collection in WPF combobox在 WPF 组合框中的集合内绑定集合
【发布时间】:2013-07-01 11:18:00
【问题描述】:
ObservableCollection<A> work = new ObservableCollection<A>();     
Class A
{
     int a;
     int b;
    observablecollection<string> c;
}

我需要将“work”绑定为组合框的Itemsource,将selectedItem绑定为A。但是我需要在组合框中显示A类的字符串(c)。我将如何在组合框中显示字符串 C。有什么想法吗?

【问题讨论】:

  • 您是在 XAML 中绑定还是在 Code-Behind 中绑定?
  • ComboBox 的每一项都必须显示字符串列表吗?
  • 是的!这是我的要求。

标签: c# wpf data-binding combobox


【解决方案1】:

如果您需要每个ComboBoxItem 显示字符串集合,请在ItemTemplateComboBox 中使用ItemsControl

<ComboBox ItemsSource="{Binding work}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
              <TextBlock Text={Binding a} />
              <TextBlock Text={Binding b} />
              <ItemsControl ItemsSource="{Binding c}" /> 
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    相关资源
    最近更新 更多