开发者

Binding Combobox SelectedItem by a field's value

Combobox bind to a set of Provinces, Village object has ProvinceID field and i want to bind SelectedItem of Combobox to a Province with Village's ProvinceID.

My code is:

<ComboBox ItemsSource="{Binding ProvincesList}" 
          DisplayMemberPath="ProvinceName" 
          SelectedValuePath="ProvinceID" 
          SelectedValue="{Binding Village.Provinc开发者_Python百科eID}" />

But SelectedItem is anything.


Your binding direction is OneWay and BindingEngine of SL can't propagate UI changes to your object's property, hence you must add Mode=TwoWay at end of binding expression.


Not sure I understand the question, but what about setting the ComboBox's ValueMember to ProvinceID?


First thing I notice is that that is not the correct syntax for binding to a control.

   SelectedValue="{Binding Village.ProvinceID}"

Should be

   SelectedValue="<%# Village.ProvinceID %>"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜