I want to fill a ComboBox with key/value data in code behind, I have this:
XAML:
There's an easier way.
Convert the enumeration to a Generic.Dictionary object. For example let say you wanted a combo box with the weekday ( just convert the VB to C#)
Dim colWeekdays As New Generic.Dictionary(Of FirstDayOfWeek, String)
For intWeekday As FirstDayOfWeek = vbSunday To vbSaturday
colWeekdays.Add(intWeekday, WeekdayName(intWeekday))
Next
RadComboBox_Weekdays.ItemsSource = colWeekdays
In your XAML you only need to set the following to bind to an object:
SelectedValue="{Binding Path= StartDayNumberOfWeeek}" SelectedValuePath="Key"
DisplayMemberPath="Value" />
The code above can easily be generalized using reflection to handle any enumerations.
hope this helps
The way DevExpress 17.1.7 handles this is setting those properties: DisplayMember
and ValueMember
, in case of a dictionary it would be something like this:
DisplayMember="Value"
ValueMember="Key"
To your ComboBox add
SelectedValuePath="Key" DisplayMemberPath="Value"