Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change WPF ComboBox dropdown width in C#

Tags:

c#

combobox

wpf

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 !!!!

like image 779
Joël Phaka Avatar asked Jan 17 '15 23:01

Joël Phaka


People also ask

How do I change the width of a combobox in C#?

// Set the size of the combobox mybox. Size = new Size(216, 26);

What is combo box WPF?

A combobox is a selection control that combines a non-editable textbox and a drop-down listbox that allows users to select an item from a list. It either displays the current selection or is empty if there is no selected item.


1 Answers

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>
like image 179
SamTh3D3v Avatar answered Oct 10 '22 02:10

SamTh3D3v