首页 > 解决方案 > 如何使用带有内部列表的列表集合表示 wpf 中的数据

问题描述

当每个属性都包含他的名称和值列表时,我如何表示我的属性集合(列表)?内部列表(值)通常具有不同的长度。我正在使用 wpf。我试图使用 DataGrid 但无法正确绑定集合

标签: c#wpfxaml

解决方案


您可以将 ItemsControl 与 ItemTemplate 属性设置为 DataTemplate 与另一个 ItemsControl 一起使用,如下所示:

> <ItemsControl ItemsSource="{Binding OuterList}">
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <TextBlock Text="{Binding Name}" />            
        <ItemsControl ItemsSource="{Binding InnerList}" />
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>

推荐阅读