XAML technology: An easy implementation of editable ComboBox in Silverlight

Source: Internet
Author: User
Tags silverlight

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"/> &lt ; 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.