在combobox 同时显示图片,文字,如图:
引用:using System.Windows.Media.Imaging;
功能函数如下:
/// <summary>
/// combobox 下拉同時顯示 圖片文字
/// </summary>
/// <param name="_cmbImg"></param>
/// <param name="ImgPath"></param>
/// <param name="Title"></param>
/// <returns></returns>
public void cmbImg( ComboBox _cmbImg, string ImgPath, string Title)
{
BitmapImage bitmap = new BitmapImage();
bitmap.UriSource = new Uri(ImgPath, UriKind.Relative);
Image img = new Image()
{
Width = 20,
Height = 15,
Margin = new Thickness(0),
Source = bitmap,
// Tag = "Images/ColorCard/" + str
};
Label lbl = new Label()
{
Content =Title ,
FontFamily = new FontFamily("Arial"),
FontSize =15
};
StackPanel stackPanels = new StackPanel();
stackPanels.Orientation = Orientation.Horizontal;//水平 Orientation.Horizontal,垂直 Orientation.Vertical
stackPanels.Children.Add(img);
stackPanels.Children.Add(lbl);
ComboBoxItem multipleCmb = new ComboBoxItem();
multipleCmb.Content = stackPanels;
_cmbImg.Items.Add(multipleCmb);
}
此功能函数有些不足之处:当在选择着 如 1516 粉红色,如何取得 1516这个值?请大家帮助想想,有什么办法可以解决?