开发者

Combobox and its item display problem wpf

I am using the following code to display items in the combobox. but item is not getting displayed.

Code:

<ComboBox Width="100" ItemsSource="{Binding}" SelectedIndex="0" Name="cbProduct"/>
  List<ComboObject> combObjList = new List<ComboObject>();

 开发者_如何学Go       combObjList.Add(new ComboObject { Text = "All", Value = "%" });
        combObjList.Add(new ComboObject { Text = "Music", Value = "1" });
        combObjList.Add(new ComboObject { Text = "Games", Value = "2" });
        combObjList.Add(new ComboObject { Text = "Video", Value = "3" });

        cbProduct.DataContext= combObjList;
        cbProduct.DisplayMemberPath = "Text";
        cbProduct.SelectedValuePath = "Value"; 


Make sure that the properties you are binding to have a 'get' defined.

public ObservableCollection<ComboObject> CombObjList
    {
        get { return combObjList; }
    }
    private ObservableCollection<ComboObject> combObjList = new ObservableCollection<ComboObject>();

class ComboObject
{
    public string Text { get; set; }
    public string Value { get; set; }
}

Also, take a look at your 'Output' window do see if you are having any Binding errors.

Hope this helps!


Have you Tried DisplayMemberPath attribute on Combo Box?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜