WPF ComboBox: static list of ComboBoxItems, but databound SelectedItem?

前端 未结 1 1006
心在旅途
心在旅途 2021-02-19 05:47

In my WPF application, I have a ComboBox that is filled with a static list of ComboBoxItems because its contents will never change. However, because I want to databind the Selec

1条回答
  •  清歌不尽
    2021-02-19 06:30

    If you use SelectedValuePath then you need to bind to the SelectedValue property which is

    Gets or sets the value of the SelectedItem, obtained by using SelectedValuePath

    So modify your binding to

    SelectedValue="{Binding Path=Amount, Mode=TwoWay}" 
    

    because as you experienced the SelectedItem will always contain the actually selected item (in your case the ComboBoxItem) not the value.

    0 讨论(0)
提交回复
热议问题