Binding List of Lists in XAML?

前端 未结 1 403
北海茫月
北海茫月 2020-12-09 13:09

I have a List of Lists object:

List> MovieList

This MovieList object is a collection of lists of movies, each based

相关标签:
1条回答
  • 2020-12-09 13:58

    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>
    
    0 讨论(0)
提交回复
热议问题