如何使用列表作为组合框的项目源? [英] how do i use a List as an itemsource for a Combobox?

查看:61
本文介绍了如何使用列表作为组合框的项目源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我已经创建了一个List< string>数据;我向其中添加了许多字符串的属性.

我将此用作我的组合框的itemssource.
在这种情况下,我应该使用什么作为DisplayMemberPath.目前,我的组合框没有显示任何数据.

Hi! i have created a List<string> data; property that i have added many string to.

i use this as a itemssource for my combobox.
In this case what should i use as the DisplayMemberPath. At the moment my combobox isn''t displaying any data.

public List<string> Country { get; set; }
                    Country = e.Result.Select(x => x.Country).Distinct().ToList();

                    SolvingTimeData = e.Result;
                    ComboBoxCountry.ItemsSource = Country;
//                    ComboBoxCountry.DisplayMemberPath = "";
                    ComboBoxCountry.SelectedItem = 0;</string>




谢谢!




Thanks!

推荐答案

您如何在xaml中设置绑定?通常,您将在xaml中设置ItemsSource,然后在后面的代码中将DataContext设置为List<string></string>诸如此类

How have you set the binding in the xaml? Normally you would set the ItemsSource in the xaml, and then in your code behind you would set the DataContext to the List<string></string> something like this

<ComboBox ItemsSource="{Binding}" Name="cbo"/>

并在您的代码中

and in your code behind

List<string> countries = new List<string>();
          //fill list
          cbo.DataContext = countries;



希望对您有帮助



Hope this helps


这篇关于如何使用列表作为组合框的项目源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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