How to bind a list of item in CollectionViewSource?

后端 未结 1 1285
野趣味
野趣味 2021-01-26 08:37

I\'m stuck in this problem for days. Never found a solution. So I\'ve a list of items called Country, in this list I\'ve also another list of items called Lea

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-26 09:21

    I went by the output you want. Please check and tell if this is what you want.

    public partial class WinExpander : Window
    {
        public WinExpander()
        {
            InitializeComponent();
    
            this.DataContext = new ViewModel();
        }
    } 
    
    public class ViewModel
        {
            public List Countries { get; set; }
            public ViewModel()
            {
                Countries = new List();
            }
        }
    
    public class Country
        {
            public string Name { get; set; }
            public List Leagues { get; set; }
    
            public Country()
            {
                Leagues = new List();
            }
        }
    
        public class League
        {
            public string Name { get; set; }
            public List Matches { get; set; }
    
            public League()
            {
                Matches = new List();
            }
        }
    
        public class Match
        {
            public string Name { get; set; }
        }
    

    XAML

    
        
    
    ...
    
                
                    
                        
                            
                                
                                    
                                        
                                            
                                                
                                                    
                                                        
                                                    
                                                
                                            
                                        
                                    
                                
                            
                                 
                    
                
     
    

    You can replace any of the ItemsControl with ListBox too.

    Another solution using GroupStyle and ListView according to user requirements.

    
         
             
         
    
    ...
    
        
            
                
                                        
                    
                        
                            
                                
                                    
                                        
                                            
                                        
                                    
                                
                            
                        
                    
                
            
        
        
            
                
                    
                
            
        
    
    

    0 讨论(0)
提交回复
热议问题