[英]Grid columns and rows in ComboBox
我的comboBox中有30個項目。 我正在尋找在組合框中添加列和行的方法。
這是我想做的:
組合框有4列7行(行= itemCount /列)。
物品類別:
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>
將此元素添加到XAML中的組合框:
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="7" Columns="4" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
(但是您知道7x4小於30嗎?):-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.