的DisplayMemberPath给出了一个错误,当我尝试使用它在组合框显示我的字典的价值 [英] DisplayMemberPath gives an error when I try to use it to display the value of my dictionary in a Combo Box

查看:320
本文介绍了的DisplayMemberPath给出了一个错误,当我尝试使用它在组合框显示我的字典的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的组合框

<ComboBox Height="40" VerticalAlignment="Stretch" x:Name="comboBox1" Grid.Column="1" FontSize="25">
        </ComboBox>

下面是我的C#代码

var source = new Dictionary<string, double>();
        source.Add("Item1", 0.4);
        source.Add("Item2", 0.3);
        source.Add("Item3", 0.1);
        source.Add("Item4", 0.1);

        var formateDSource = new Dictionary<string, string>();

        foreach (var item in source)
        {
            formateDSource.Add(string.Format("[{0}, {1}]", item.Key, item.Value), item.Key);
        }

        comboBox1.ItemsSource = source.Values;
        comboBox1.DisplayMemberPath = "Value";

当我跑我的代码我没有看到在组合框中什么。我做了什么错?

When I run my code I don't see anything in the Combo Box. What have I done wrong?

推荐答案

你应该尝试'。'而不是价值,就应该把它捡起来作为绑定到对象,因为它没有属性名

you should try '.' instead of Value, it should pick it up as binding to the object as it has no property name

comboBox1.DisplayMemberPath = ".";

这篇关于的DisplayMemberPath给出了一个错误,当我尝试使用它在组合框显示我的字典的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆