Click here to Skip to main content
14,920,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i want to disable the dropdown of a combobox, when the property "isEditable" is set to true and vice versa. Therefore i've created a custom control which inherits from ComboBox.

After pasting the standard control template from the ComboBox into the Generic.xaml and starting the app, the combobox is only visible when i hover over with the mouse. I didn't change anything in the control template so far.

1. Shouldn't it be displayed as a normal ComboBox?

2. Is this the right approach to lock the DropDown while editing?
<Trigger Property="ComboBox.IsEditable" Value="True">
  <Setter Property="UIElement.IsEnabled" Value="False" />

1 solution

It is not clear for me what you are trying to achieve.

But if you want dropdown not to be shown when IsEditable is set to True and appear when IsEditable is False, then you can check this code (add to ControlTemplate.Triggers):

        <Condition Property="IsEditable" Value="True"></Condition>
        <Condition  Property="IsDropDownOpen" Value="True"></Condition>
    <Setter TargetName="Popup" Property="IsOpen" Value="False"></Setter>
<Trigger Property="ComboBox.IsEditable" Value="True">
    <Setter TargetName="ToggleButton" Property="IsEnabled" Value="False" />

Drop down can be shown if user clicks toggle button or presses Alt + UpArrow/DownArrow. So here we are disabling/enabling toggle button and making popup show logic depend on IsEditable.
maschle 17-Dec-12 10:14am
thank you for the answer but i have to make my own custom control and i read that the combobox has two different control templates depending on if it is Editable or not. So how can i change between these two?
Ivan Leonenko 17-Dec-12 10:56am
You can still make custom control and apply styles and control templates to them, if you inherit from ComboBox . Or you can use the same approach the default style & control template for ComboBox using, IsEditable does only this:
<Trigger Property="IsEditable" Value="true">
<setter property="IsTabStop" value="false"></setter>
<setter targetname="PART_EditableTextBox" property="Visibility" value="Visible"></setter>
<setter targetname="ContentSite" property="Visibility" value="Hidden"></setter>
Member 10093728 8-Dec-14 23:59pm

I tried your above solution but I am getting this error: "The name "Popup" is not recognized." and "The name "ToggleButton" is not recognized.:.

How can I resolve the same?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900