Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ComboBox with editable textbox as an item

I'm looking to have a combo box with only two items:

-----------
|  Other.. |
------------
|  TextBox |
------------

Text Box representing a physical textbox that can be editable and Other.. being just a regular combobox item.

Can someone help me out on how I will need to edit it.

I have tried changing the Combbox.itemtemplate with a stackpanel and then adding a textbox, but it didn't show up and that also stops the chance of me having a regular combobox item in the control.

Thanks in advance.

like image 713
Sandeep Bansal Avatar asked Jul 31 '11 23:07

Sandeep Bansal


2 Answers

Have you tried setting ComboBox.IsEditable = true? Then you'll need just one item and the ComboBox.Text property.

like image 95
XAMeLi Avatar answered Nov 07 '22 15:11

XAMeLi


Not quite sure what the problem is, have you tried this:

<ComboBox>
    <ComboBoxItem>Other</ComboBoxItem>
    <TextBox>TextBox</TextBox>
</ComboBox>

If this is not what you want, please explain what exactly you need...


(The TextBox-item might be quite hard to select so giving it a label which can be clicked might be of interest)

<ComboBox>
    <ComboBoxItem>Normal Item</ComboBoxItem>
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Other: " VerticalAlignment="Center"/>
        <TextBox>Enter text...</TextBox>
    </StackPanel>
</ComboBox>
like image 41
H.B. Avatar answered Nov 07 '22 17:11

H.B.