Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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?
XML
<Trigger Property="ComboBox.IsEditable" Value="True">
  <Setter Property="UIElement.IsEnabled" Value="False" />
</Trigger>
Posted

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):

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


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.
 
Share this answer
 
Comments
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 http://msdn.microsoft.com/en-us/library/ms752094(v=vs.85).aspx . 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>
</Trigger>
Member 10093728 8-Dec-14 23:59pm    
Hi,

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?

Thanks,
AJ

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