In the database, table TblPerson
has a CHAR(1)
field called Gender
with a check constraint on possible values null, 'M' and 'F'
I'm trying to display (and two-way bind) the (EF mapped to type string
) TblPerson.Gender
property inside a ComboBox
, but I don't seem to be get it to work.
I bind my other controls ( TextBox
es) to the same TblPerson
object without issues. Have set an ItemsSource
according to the check constraint:
comboBoxGender.ItemsSource = new char[] { '\0', 'M', 'F' };
But then I fail to grasp the link between the ItemsSource
and the binding of the object property.
I'm not even trying to show 'male' or 'female' and link that to 'M' and 'F', so I don't think I need a converter (or do I?)
So what do I do with those (in)famous three ComboBox
properties I need to set to make this work?
Been at this for some time, haven't made the click yet. Yes, I've read Microsofts How to: Use SelectedValue, SelectedValuePath, and SelectedItem .
TblPerson.Gender和您的ItemsSource项必须为同一类型。
First of all, forget the "Tbl" naming. Entities are not tables. Entities are Entities.
Second, don't manipulate UI elements' properties in procedural code.
Thid, just use SelectedItem
and you're good to go.
<ComboBox ItemsSource={Binding SomeList} SelectedItem={Binding Person.Gender}/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.