6

I'm currently working on C# WPF project, one thing I can't seem to do is - How do I change the ComboBox dropdown width, because every time I had Items the dropdown width takes the size of the longest item(or string);

How can I fix this Please Help fellow developers/programmers !!!!

4
  • What exactly do you want the drop down width to be? Commented Jan 17, 2015 at 23:52
  • You can simply set an absolute width on the template you use to show the items. Commented Jan 17, 2015 at 23:58
  • There are several ways to do that. Simply, bind ComboBoxItem.Width to the ComboBox.ActualWidth Commented Jan 17, 2015 at 23:59
  • Hamlet Hakobyan ; How do I go about that ? Commented Jan 19, 2015 at 1:29

1 Answer 1

12

Set the ItemContainerStyle of the ComboBoxItem like this:

 <ComboBox Width="50" Height="40">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="ComboBoxItem">
                <Setter Property="Width" Value="60"/>
            </Style>
        </ComboBox.ItemContainerStyle>
        <ComboBoxItem Content="this is Item One "/>
        <ComboBoxItem Content="this is Item "/>
        <ComboBoxItem Content="this is "/>
        <ComboBoxItem Content="this "/>
    </ComboBox>
Sign up to request clarification or add additional context in comments.

2 Comments

Also there is the MaxHeight attribute that might be usefull
This affects the container, not the dropdown itself. For instance, I set it to 200 but my ComboBox itself was 1000, so this content appeared centered in the dropdown. What I'm trying to do is limit the width of the dropdown to match the combo box itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.