WPF ListView with horizontal arrangement of items?

前端 未结 5 1118
粉色の甜心
粉色の甜心 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:39

    I recently research how to achieve this in WPF and found a good solution. What I wanted was to the replicate the List mode in Windows Explorer, i.e. top-to-bottom, then left-to-right.

    Basically what you want to do override the ListBox.ItemsPanel property to use a WrapPanel with it's orientation set to Vertical.

    
      
              
          
        
      
    
    

    However this WILL be slow when loading a large data set as it the wrap panel is not virtualised. This is important. So this task now becomes a little more as now you need to write your own VirtualizedWrapPanel by extending VirtualizedPanel and implementing IScrollInfo.

    public class VirtualizedWrapPanel : VirtualizedPanel, IScrollInfo
    {
       // ...
    }
    

    This is as far as I got in my research before having to go off to another task. If you want more information or examples, please comment.

    UPDATE. Ben Constable's has a great series on how to implement IScrollInfo.

    There are 4 articles in total. A really good read.

    I have since implemented a virtualized wrap panel, it is not an easy task even with the help of the above series of articles.

提交回复
热议问题