Listview win8 xaml how to create columns?

后端 未结 2 598
日久生厌
日久生厌 2020-12-10 07:58

Hi I am trying to create 3 columns in a ListView.

I read this but I want to set the data in each column programtically in C#:

how to display data in rows and

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 08:59

    Assuming you have something like this to store your data:

    public class SongDetails
    {
        public string ArtistName {get; set;}
        public string SongName {get; set;}
        public string Artist {get; set;}
    }
    

    And a ListView with a DataTemplate defined (as in the link you provided), just give your ListView a name:

    
        
            
                
    
                    
                        
                        
                        
                    
    
                    
                    
                    
                
            
        
    
    

    Then, from the code-behind, it's just a case of:

    var songDetails = new[]
        {
            new SongDetails {Artist = "a1", ArtistName = "a2", SongName = "a3"},
            new SongDetails {Artist = "b1", ArtistName = "b2", SongName = "b3"}
        };
    
    ListViewSongs.ItemsSource = songDetails;
    

提交回复
热议问题