【问题标题】:WPF nested ListView ItemsSourceWPF 嵌套 ListView ItemsSource
【发布时间】:2014-04-20 20:17:48
【问题描述】:

我有以下数据模型:

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

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

我有一个 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>

但是,我想要一个水平的项目列表(嵌套的 ListView) - 但我不知道为嵌套的 ListView 设置什么作为 ItemsSource。

【问题讨论】:

标签: c# wpf listview windows-store-apps


【解决方案1】:

假设外部ListView 绑定到Item 列表,那么内部ListView.ItemsSource 应该绑定到SubItems 属性

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

【讨论】:

    猜你喜欢
    • 2011-01-14
    • 2014-01-26
    • 2014-12-08
    • 1970-01-01
    • 2010-11-13
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多