WPF ListView with horizontal arrangement of items?

前端 未结 5 1163
粉色の甜心
粉色の甜心 2020-11-28 04:44

I want to lay out items in a ListView in a similar manner to the WinForms ListView in List mode. That is, where items are laid out not just vertically but horizontally in th

5条回答
  •  时光说笑
    2020-11-28 05:42

    In addition to @Dennis's answer, about the WrapPanel losing Virtualization, I have found a nice class that correctly implements this. While the suggested post by Ben Constable (Part 1, Part 2, Part 3, Part 4) is a nice introduction, I couldn't quite complete the task for a Wrap Panel.

    Here is an implementation: https://virtualwrappanel.codeplex.com/ I've tested it with total of 3.300 video's and photo's, loading the list itself is of course a bit long, but eventually it is correctly virtualizing the list, no scroll lag whatsoever.

    • There are some issues to this code, see the issues tab on the page above.

    After adding the source code to your project, example source code:

       
      
       
    
        
            
                
                    
                
            
            
                
                    
                        
                        
                        
    
                    
                
            
        
    

    MVVM style back-end, so this is inside the ViewModel:

        public ObservableCollection ListImages
        {
            get
            {
                return listImages;
            }
            set { listImages = value; OnPropertyChanged(); }
        }
    
    
         //Just load the images however you do it, then assign it to above list.
    //Below is the class defined that I have used.
    public class Media
    {
        private static int nextMediaId = 1;
        public int mediaId { get; }
        public string title { get; set; }
        public string path { get; set; }
        public DateTime createDate { get; set; }
        public bool isSelected { get; set; }
    
        public Media()
        {
            mediaId = nextMediaId;
            nextMediaId++;
        }
    }
    

提交回复
热议问题