Reputation: 359
I have 30 items in comboBox. I'm looking for the way to add columns and rows in a combobox.
Here is what I want to do:
The combobox have 4 columns, 7 rows (row = itemCount/columns).
Item class:
public class ItemSymbol{
public string ImageName{
get; set;
}
public string Comment{
get; set;
}
}
ViewModel:
List<ItemSymbol> lstsymbol=new List<ItemSymbol>(30){
new ItemSymbol(){ImageName=@"Resources\bunny.png",Comment="funny"},
new ItemSymbol(){ImageName=@"Resources\hand.png",Comment="communication"},
new ItemSymbol(){ImageName=@"Resources\heart1.png",Comment="love"},
new ItemSymbol(){ImageName=@"Resources\heart2.png",Comment="love"}
};
Window1.xaml:
<ComboBox x:Name="cbo"
ItemsSource="{Binding lstsymbol}"
SelectedItem="{Binding SelectedItem}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Width="30" Height="30"
Source="{Binding ImageRes}" Margin="5" ToolTip="{Binding Comment}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Upvotes: 0
Views: 187
Reputation: 5797
Add this element to your Combobox in XAML:
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="7" Columns="4" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
(But you know that 7x4 is less then 30?) :-)
Upvotes: 1