Binding data to ComboBox WPF

前端 未结 3 1166
情歌与酒
情歌与酒 2021-01-25 13:51

I am newbie to WPF, and needs help to bind data into the ComboBox. The xaml file contains the tag below.



        
3条回答
  •  没有蜡笔的小新
    2021-01-25 14:03

    If your Inbox class is like,

    public class Inbox
    {
        public int ID { get; set; }
        public string Text { get; set; }
    }
    

    And if you do not want to change your xmal, the code behind method should be like this,

    public void FillInboxes(List inboxes) 
        {
            _currentInbox.DisplayMemberPath = "Text"; // To display the 'Text' property in the combobox dropdown
            //_currentInbox.DisplayMemberPath = "ID"; // To display the 'ID' property in the combobox dropdown
            _currentInbox.DataContext = inboxes; 
        }
    

提交回复
热议问题