XAML中的列表绑定列表?

[英]Binding List of Lists in XAML?


I have a List of Lists object:

我有一个列表列表对象:

List<List<Movie>> MovieList

This MovieList object is a collection of lists of movies, each based on a particular movie genre. ex. MovieList[0] will be a list of movies of Comedy genre, and so on Now I want to bind this List of Lists MovieList object to a ListView in XAML. The ListView ItemSource is to be bound to this MovieList object and each ListViewItem of this ListView will be a ListView itself, bound to the list of movies of a particular genre. ex. list of movies of comedy genre. Further each ListViewItem of this inner List will be bound to the Title property of that particular movie. Please help me out in designing the XAML Code for this.

该MovieList对象是电影列表的集合,每个电影列表基于特定的电影类型。恩。 MovieList [0]将是喜剧类型的电影列表,依此类推现在我想将这个列表列表MovieList对象绑定到XAML中的ListView。 ListView ItemSource将绑定到此MovieList对象,此ListView的每个ListViewItem将是ListView本身,绑定到特定类型的电影列表。恩。喜剧类型电影列表。此外,此内部List的每个ListViewItem都将绑定到该特定影片的Title属性。请帮我设计XAML代码。

1 个解决方案

#1


12  

MVVM solution:

MVVM解决方案:

MainWindow:

主窗口:

var moviesView = new MoviesView();
moviesView.DataContext = new MoviesViewModel { MovieList = ... };

MoviesViewModel.cs:

MoviesViewModel.cs:

public class MoviesViewModel
{
    public ObservableCollection<List<Movie>> MovieList 
    { 
        get; 
        set; 
    }
}

MoviesView.xaml

MoviesView.xaml

<ListView ItemsSource="{Binding MovieList}">
   <ListView.ItemTemplate>
      <DataTemplate>
            <ListView ItemsSource="{Binding}">
               <ListView.ItemTemplate>
                   <DataTemplate>
                         <TextBlock Text="{Binding Title}" />
                   </DataTemplate>
               </ListView.ItemTemplate>
            </ListView>
      </DataTemplate>
   </ListView.ItemTemplate>
</ListView>
关注微信公众号

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/11/18/60e75f454aff9aeff08b21a178be6d03.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com