简体   繁体   English

ComboBox中的网格列和行

[英]Grid columns and rows in ComboBox

I have 30 items in comboBox. 我的comboBox中有30个项目。 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). 组合框有4列7行(行= itemCount /列)。
Item class: 物品类别:

public class ItemSymbol{
   public string ImageName{
     get; set;
   }

   public string Comment{
     get; set;
   }
}

ViewModel: 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: 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>

Add this element to your Combobox in XAML: 将此元素添加到XAML中的组合框:

<ComboBox.ItemsPanel>
    <ItemsPanelTemplate>
        <UniformGrid Rows="7" Columns="4" />
    </ItemsPanelTemplate>
</ComboBox.ItemsPanel>

(But you know that 7x4 is less then 30?) :-) (但是您知道7x4小于30吗?):-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM