Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
112 views
Welcome To Ask or Share your Answers For Others

1 Answer

MVVM solution:

MainWindow:

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

MoviesViewModel.cs:

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

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...