I am newbie to WPF, and needs help to bind data into the ComboBox. The xaml file contains the tag below.
I assume your Inbox
class consists of two properties (for simplicity), but there may be any number of them:
public class Inbox
{
public int ID { get; set; }
public string Text { get; set; }
}
You write a DataTemplate
, for example:
:
Then correct your ComboBox declaration like:
Finally you set DataContext
of your ComboBox to your List
:
public void FillInboxes(List inboxes)
{
_currentInbox.DataContext = inboxes;
}
EDIT: As you've asked for a simpler solution, you can just override ToString()
method of your Inbox
class:
protected override string ToString()
{
return ID.ToString() + ":" + Text;
}