【问题标题】:WPF: Binding the items in a "sub-list" of a listWPF:绑定列表的“子列表”中的项目
【发布时间】:2015-05-06 16:46:42
【问题描述】:

我在 WPF 中有一个 Datagrid,我绑定到我的 ObservableCollection 列表,然后为我想要的属性创建列,如下所示:

    public int Name { get; set; }
    public DateTime Date { get; set; }
    public long Cod { get; set; }
    public long ProductRef{ get; set; }

    public List<SubProduct> ListSpecs {get; set;}

问题是,该集合有一个子产品列表,我需要至少为该列表的第一个项目创建一个新列。数据网格如下所示:

|Name|Date|Cod|ProductRef|ListSpecs[0]|ListSpecs[1]|

如何实现?我不想添加更多属性来绑定该列表的项目。

【问题讨论】:

    标签: c# wpf xaml binding datagrid


    【解决方案1】:

    以下应该有效。例如,对于您的子集合的第一项。 或者您可以尝试将整个子集合绑定到组合框?

            <DataGrid.Columns>
                <DataGridTextColumn Header="item" Binding="{Binding Name}"  />
                <DataGridTextColumn Header="subitems" Binding="{Binding ListSpecs[0]}"  />  // first item of subcollection
                <DataGridTextColumn Header="subitems" Binding="{Binding ListSpecs[1]}"  /> // second item of sub collection
            </DataGrid.Columns>    
        </DataGrid>
    

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      相关资源
      最近更新 更多