zoukankan      html  css  js  c++  java
  • silverlight combobox image label

    在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这个值?请大家帮助想想,有什么办法可以解决?

  • 相关阅读:
    常用Git代码托管服务分享
    .NET中操作IPicture、IPictureDisp
    Git学习笔记与IntelliJ IDEA整合
    螺旋队列问题
    杂题3道
    .NET 配置文件简单使用
    C++之Effective STL
    不容易理解的 lock 和 merge
    状态模式
    观察者模式
  • 原文地址:https://www.cnblogs.com/aran/p/2118550.html
Copyright © 2011-2022 走看看