DisplayMemberPath gives an error when I try to use it to display the value of my dictionary in a Combo Box

前端 未结 2 1259
情书的邮戳
情书的邮戳 2021-01-25 04:59

Here is my Combo Box


                 


        
2条回答
  •  太阳男子
    2021-01-25 05:29

    Try this:

    
    
    var source = new Dictionary();
                source.Add("Item1", 0.4);
                source.Add("Item2", 0.3);
                source.Add("Item3", 0.1);
                source.Add("Item4", 0.1);
    
                var formateDSource = new Dictionary();
    
                foreach (var item in source)
                {
                    formateDSource.Add(string.Format("[{0}, {1}]", item.Key, item.Value), item.Key);
                }
    
                comboBox1.ItemsSource = source;
    

提交回复
热议问题