I’m binding a List<SelectItem> to a ComboBox using MVVM. The combobox has the right value and looks fine. However, when I click on the down button to see all the options in the combobox, I get a list of 10 items that each read MyNamespace.SelectItem. If I select #2, the value in the combobox then reads 2.
Here’s the code for SelectItem:
public class SelectItem
{
public string Value { get; set; }
public string Display { get; set; }
}
My XAML:
<ComboBox ItemsSource="{Binding Path=MyList}" DisplayMemberPath="Display" SelectedValue="{Binding Path=MyListValue, Mode=TwoWay}" />
And here’s where I queue up a list of SelectItems:
MyList= new List<SelectItem>();
for (int i = 1; i <= 10; i++)
{
var page = new SelectItem()
{
Display = i.ToString(),
Value = i.ToString()
};
MyList.Add(page);
if (i == 1)
MyListValue = page;
}
Check for any typo.
With following code:
Initialization:
XAML:
I was able to see numbers in the
ComboBox. No type names.