C # WPF Combobox drop-down list for multiple columns

Is it possible to "make" the elements of a list with a list in a list appear in two columns?

For example, for example:

Selected item CB

CB Paragraph 1 | CB Paragraph 4

CB Paragraph 2 | CB Point 5

CB Paragraph 3 |

+4
source share
4 answers

You can change the ItemsPanel to a WrapPanel, just be careful at the height (you can write a converter to calculate it according to the number of elements):

<ComboBox> <ComboBox.Resources> <Style TargetType="ComboBox"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" Orientation="Vertical" Width="100" Height="50" /> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="ComboBoxItem"> <Setter Property="Width" Value="50" /> </Style> </ComboBox.Resources> <ComboBoxItem Content="Value 1" /> <ComboBoxItem Content="Value 2" /> <ComboBoxItem Content="Value 3" /> <ComboBoxItem Content="Value 4" /> <ComboBoxItem Content="Value 5" /> </ComboBox> 
+5
source

Well, you can XAML here:

 <ComboBox Name="ComboBox"> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="2"/> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> 

Now a simple test, adding numbers from 0 to 8, gives:

uniform grid in combo box

Now you can style everything you want ... :)

Of course, each element (each number, in this particular case) is a separate, clickable element, simply because there are no misunderstandings.

[EDIT] I just noticed that you want to do it the other way around, that is, in the direction of the "lines", if so, then it might be better to use a WrapPanel , and someone suggested an answer in another. UniformGrid first fills the grid in the column.

Maybe there is a way to do this with UniformGrid , but there is no explicit and simple change with one click (I was not here before :)

+6
source

You will need to put the WrapPanel in the ItemsPanel drop-down list.

 <ComboBox> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" Height="100" /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> <ComboBoxItem Content="Value 1" /> <ComboBoxItem Content="Value 2" /> <ComboBoxItem Content="Value 3" /> <ComboBoxItem Content="Value 4" /> <ComboBoxItem Content="Value 5" /> <ComboBoxItem Content="Value 6" /> <ComboBoxItem Content="Value 7" /> <ComboBoxItem Content="Value 8" /> <ComboBoxItem Content="Value 9" /> <ComboBoxItem Content="Value 10" /> <ComboBoxItem Content="Value 11" /> <ComboBoxItem Content="Value 12" /> <ComboBoxItem Content="Value 13" /> <ComboBoxItem Content="Value 14" /> <ComboBoxItem Content="Value 15" /> </ComboBox> 

enter image description here

+2
source

you can try modifying the control pattern to use the Grid and use transforms to determine which column and row are cbitems. I am not sure how you will handle the selected item.

0
source

All Articles