How To Bind a Combobox to a Dictionary in WPF C#
回答1
Use a Dictionary<Answer,string>
(no need for another class)
AnswerDisplay = new Dictionary<Answer, string>
{
{Answer.YES, "I will do it"},
{Answer.NO, "I will not do it"},
{Answer.MAYBE, "I might do it"},
};
and bind it to the ComboBox
<ComboBox ItemsSource="{Binding AnswerDisplay}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding SelectedAnswer}"/>
Update
If you want to use your dictionary, then change the binding to
<ComboBox ItemsSource="{Binding AnswerDisplay}"
DisplayMemberPath="Value.DisplayDescription"
SelectedValuePath="Key"
SelectedValue="{Binding SelectedAnswer}"/>
标签:Dictionary,C#,Combobox,How,Bind,Answer From: https://www.cnblogs.com/chucklu/p/16708656.html