简体   繁体   English

WPF嵌套ListView ItemsSource

[英]WPF nested ListView ItemsSource

I have a following data model: 我有以下数据模型:

class Item{
  public string Name{get;set;}
  public ObservableCollection<SubItem> SubItems {get;set;}
} 

class SubItem{
  public string Name {get;set;}
}

I have a ListView that shows an ObservableCollection fine as: 我有一个ListView ,显示ObservableCollection罚款为:

        <ListView x:Name="lvResult" Background="DeepPink" Grid.Row="1" ItemsSource="{Binding}">
                <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding }" FontWeight="Bold"/>
                        <ListView Background="Black" Margin="8,0,0,0">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                        </ListView>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

However, I'd like to have a horizontal list of items (the nested ListView) - but I don't know what to set as ItemsSource for the nester ListView. 但是,我想有一个水平的项目列表(嵌套的ListView)-但是我不知道要为嵌套ListView设置为ItemsSource的内容。

Assuming that outer ListView is bound to list of Item then inner ListView.ItemsSource should be bound to SubItems property 假设外部ListView绑定到Item列表,则内部ListView.ItemsSource应该绑定到SubItems属性

<ListView x:Name="lvResult" ...>
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding}" FontWeight="Bold"/>
                <ListView ... ItemsSource="{Binding SubItems}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM