XAML binding list?

I have a list of List objects:

List<List<Movie>> MovieList 

This MovieList object is a collection of movie lists, each based on a specific movie genre. ex. MovieList[0] will be a list of movies of the genre Comedy, etc. Now I want to associate this list of MovieList list objects with a ListView in XAML. The ListView ItemSource must be bound to this MovieList, and each ListViewItem of this ListView will be a ListView itself associated with a list of movies of a particular genre. ex. a list of comedy movies. Next, each ListViewItem of this internal list will be bound to the Title property of this particular movie. Please help me in developing XAML code for this.

+7
source share
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> 
+12
source

All Articles