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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With