Using WrapPanel and ScrollViewer to give a multi-column Listbox in WPF

前端 未结 2 721
独厮守ぢ
独厮守ぢ 2021-01-01 03:52

I’m making a simple LOB app which loads data from an XML file and displays it in a list with a few buttons for editing.

In my first attempt, everything was ok except

2条回答
  •  再見小時候
    2021-01-01 04:31

    I believe to do this, you need to write custom code - you've got the right idea in overriding ItemsPanelTemplate, but WrapPanel doesn't order stuff the way you want it - it'll order stuff as:

    A B C D
    E F G H
    I J K L
    

    Whereas you probably want it:

    A D G J
    B E H K
    C F I L
    

    Also, by putting it in a ScrollViewer, it's like telling it that it has an infinitely sized screen, so the result will just be one row (because the ScrollViewer will give it as much room as it asks for). Writing a panel isn't hard, it's basically just two functions (Measure and Arrange).

提交回复
热议问题