I am trying to bind a ComboBox in WPF to a list of LogLevels. Class below
public class LogLevel
{
public string Label;
public byte Val;
public static List<LogLevel> GetAll()
{
return new List<LogLevel> {
new LogLevel{
Label = "None",
Val = 0
},
new LogLevel{
Label = "Info",
Val = 3
},
new LogLevel{
Label = "Error",
Val = 2
}
};
}
}
I want to be able to populate a ComboBox with the result of GetAll
and set the DisplayMemberPath to "Label"
ddlLogLevel.ItemsSource = LogLevel.GetAll();
<ComboBox DisplayMemberPath="Label" x:Name="ddlLogLevel" />
I have tried to set the values statically in the code-behind of the control as well, but the combobox has blank labels. The selecteditem and index is being populated as expected, just not sure how to get the Display value to work