The combobox control is used for programming today, but the ComboBox in Silverlight is not the same as it used to be, no matter how the settings are not editable, so come up with this soil method, the principle is to let the ComboBox and the textbox position overlap, TextBox on top.
The following actions are implemented:
1. Add ComboBox and TextBox controls to the foreground design code, and add unique identities to each space name
2. Bind the ComboBox with the TextBox.
datacontext= "{Binding elementname=textbox1,mode=onetime}
3. Add an event to the ComboBox: combobox_dropdownclosed
<canvas margin= "0,0,0,0" > <combobox height= "All" Name= "ComboBox1" width= "+" DROPDOWNC Losed= "combobox_dropdownclosed" datacontext= "{Binding elementname=textbox1,mode=onetime}" > <c Omboboxitem content= "list 1-1"/> <comboboxitem content= "list 1-2"/> < ; ComboBoxItem content= "list 1-3"/> </ComboBox> <textbox height= "Name=" TextBox1 "Width=" canvas.left= "0" canvas.top= "0"/> </Canvas> <canvas margin= "0,30,0,0" > <combobox datacontext= "{Binding elementname=textbox2, mode=onetime}" dropdownclosed= "combobox_dropd ownclosed "height=" "Name=" ComboBox2 "width=" > <comboboxitem content= "list 2-1"/> <comboboxitem content= "list 2-2"/> <comboboxitem content= "list 2-3"/> </combobox> <textbox height= "name=" TextBox2 "width="/> </Canvas>
4. Implementing event handler Functions
private void Combobox_dropdownclosed (object sender, EventArgs e) { ComboBox CMB = sender as ComboBox; BindingExpression binding = CMB. Getbindingexpression (combobox.datacontextproperty); TextBox TXT = binding. DataItem as TextBox; ComboBoxItem CBI = CMB. SelectedItem as ComboBoxItem; if (CBI! = null) Txt.text = CBI. Content.tostring (); }
Source Download: Easy implementation of editable ComboBox in Silverlight. zip