How to bind a combobox with Foreign Key in WPF MVVM

前端 未结 2 799
旧时难觅i
旧时难觅i 2021-01-06 14:02

I know that there are many questions regarding DataBinding a combobox and also there are many tutorials but I feel those tutorials hard. So, I am asking this question.

2条回答
  •  爱一瞬间的悲伤
    2021-01-06 14:55

    Try this:

    
        ItemsSource="{Binding MyGenderTypes}" 
        
        DisplayMemberPath="GenderType" 
        
        SelectedValuePath="GenderID" 
        
        SelectedValue="{Binding SelectedGenderID, Mode=TwoWay}" />
    

    You will get the combobox displaying GenderType, but the selected value will be the corresponding GenderID. Just as you wish...

提交回复
热议问题