2016-07-15 75 views
0

我在組合框中有30個項目。我正在尋找在組合框中添加列和行的方式。
這是我想做的事:組合框中的網格列和行

enter image description here

組合框有4列,7行(行= ITEMCOUNT /列)。
項目類:

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

    public string Comment{ 
    get; set; 
    } 
} 

視圖模型:

List<ItemSymbol> lstsymbol=new List<ItemSymbol>(30){ 
    new ItemSymbol(){[email protected]"Resources\bunny.png",Comment="funny"}, 
    new ItemSymbol(){[email protected]"Resources\hand.png",Comment="communication"}, 
    new ItemSymbol(){[email protected]"Resources\heart1.png",Comment="love"}, 
    new ItemSymbol(){[email protected]"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> 

回答

1

這個元素添加到您的組合框的XAML:

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

(但你知道,7x4的是小於30?):-)

+0

是的,我知道that.thank!這是working.How調整均勻的寬度高度,以適應有內容@Fratyx – Jandy

+0

您的意思是UnformGrid的屏幕大小或行數和列數。 – Fratyx

+0

我更新了[email protected] – Jandy